Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 94373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:29:29+00:00 2026-05-10T23:29:29+00:00

I want to provide a piece of Javascript code that will work on any

  • 0

I want to provide a piece of Javascript code that will work on any website where it is included, but it always needs to get more data (or even modify data) on the server where the Javascript is hosted. I know that there are security restrictions in place for obvious reasons.

Consider index.html hosted on xyz.com containing the following:

<script type='text/javascript' src='http://abc.com/some.js'></script> 

Will some.js be able to use XMLHttpRequest to post data to abc.com? In other words, is abc.com implicitly trusted because we loaded Javascript from there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:29:30+00:00Added an answer on May 10, 2026 at 11:29 pm

    Will some.js be able to use XMLHttpRequest to post data to abc.com? In other words, is abc.com implicitly trusted because we loaded Javascript from there?

    No, because the script is loaded on to a seperate domain it will not have access…

    If you trust the data source then maybe JSONP would be the better option. JSONP involves dynamically adding new SCRIPT elements to the page with the SRC set to another domain, with a callback set as a parameter in the query string. For example:

    function getJSON(URL,success){     var ud = 'json'+(Math.random()*100).toString().replace(/\./g,'');     window[ud]= function(o){         success&&success(o);     };     document.getElementsByTagName('body')[0].appendChild((function(){         var s = document.createElement('script');         s.type = 'text/javascript';         s.src = URL.replace('callback=?','callback='+ud);         return s;     })()); }  getJSON('http://YOUR-DOMAIN.com/script.php?dataName=john&dataAge=99&callback=?',function(data){     var success = data.flag === 'successful';     if(success) {         alert('The POST to abc.com WORKED SUCCESSFULLY');     } }); 

    So, you’ll need to host your own script which could use PHP/CURL to post to the abc.com domain and then will output the response in JSONP format:

    I’m not too great with PHP, but maybe something like this:

    <?php     /* Grab the variables */     $postURL = $_GET['posturl'];     $postData['name'] = $_GET['dataName'];     $postData['age'] = $_GET['dataAge'];      /* Here, POST to abc.com */     /* MORE INFO: http://uk3.php.net/curl & http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html */      /* Fake data (just for this example:) */     $postResponse = 'blahblahblah';     $postSuccess = TRUE;      /* Once you've done that, you can output a JSONP response */     /* Remember JSON format == 'JavaScript Object Notation' - e.g. {'foo':{'bar':'foo'}} */     echo $_GET['callback'] . '({';     echo ''flag':' . $postSuccess . ',';     echo ''response':' . $postResponse . '})';  ?> 

    So, your server, which you have control over, will act as a medium between the client and abc.com, you’ll send the response back to the client in JSON format so it can be understood and used by the JavaScript…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 68k
  • Answers 68k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Try this: WITH Nodes AS ( --initialization SELECT ParentNodeID, NodeID,… May 11, 2026 at 12:04 pm
  • added an answer The sample code uses symbols to get at three things:… May 11, 2026 at 12:04 pm
  • added an answer Depending on the specific context in which you will use… May 11, 2026 at 12:04 pm

Related Questions

I want to provide a piece of Javascript code that will work on any
I want to create a right click context menu for my textboxes to provide
I want to use RSpec mocks to provide canned input to a block. Ruby:
I'm working on a resource management class and want to have the user provide
I want to have a select-only ComboBox that provides a list of items for
I want to provide silverlight app to my customer while hosting the app at
I want to provide dynamic download of files. These files can be generated on-the-fly
If I want to provide OpenID as the only registration method available AND want
I want to have the context menu of links provide me an option to
I want to answer questions about data in Erlang: count things, correlate messages, provide

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.