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

  • Home
  • SEARCH
  • 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

Related Questions

Loading...

Sidebar

Ask A Question

Stats

  • Questions 54k
  • Answers 54k
  • 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 Define a stylesheet and set these styles up somewhere: /**… May 11, 2026 at 7:28 am
  • added an answer You can simply use: _root[tabName] To access the movieclip with… May 11, 2026 at 7:28 am
  • added an answer You can use the SET command. The following is the… May 11, 2026 at 7:27 am

Top Members

Trending Tags

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

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.