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 3342666
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:51:56+00:00 2026-05-18T00:51:56+00:00

I know that this is a popular topic, but I’ve yet to find an

  • 0

I know that this is a popular topic, but I’ve yet to find an answer that’s completely comprehensive.

I’m trying to create a simple way for our ‘customers’ to place a Google Map on their website, which plots the position of our customers (or a subset thereof) on the map. The customers are in a MySQL database which is turned into XML on-the-fly by a PHP script (as per Google’s example). This works fine on my website, but when I try it on another website the xmlHTTPRequest is not allowed to look at the PHP as it’s on another domain.

I can circumvent this by writing another PHP file on the other domain which simply reads the PHP file on the original domain. But not all our customers will have PHP running on their servers. Is there any way that I can return the XML results from our database using JavaScript?

A couple of points:

  1. The JavaScript that makes the xmlHTTPRequest still sits on our server — our clients link to it from a script tag. I thought that might be enough, but the ‘origin’ (according to Chrome, anyway) is still seen as domain#2

  2. This is great: if I use an absolute reference in the xmlHTTPRequest (e.g. request.open(‘GET’, ‘http://mydomain.com/api/foo.php’, true)) then it will fail in IE, but if I use a relative reference (‘/api/foo.php’) it will work.

  3. I don’t know enough about it, but could I use JSON? I’ve seen:
    ‘script src=”http://…./someData.js?callback=some_func”‘
    but don’t know how, I would make ‘someData.js’ look like JSON? (I’m thinking very much in terms of functions, which probably is incorrect?).

  4. I’ve tried adding:
    header(“Access-Control-Allow-Origin: *”);
    to the top of the PHP that outputs the XML, but it’s not really doing much that I can tell!

  5. If I do use a PHP wrapper on the client’s server, what’s the advantage of using a cURL request, rather that simple file_get_contents or fopen?

Sorry, lots of questions, but any guidance would be greatly appreciated.

Massive thanks,

Mat

  • 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. Editorial Team
    Editorial Team
    2026-05-18T00:51:56+00:00Added an answer on May 18, 2026 at 12:51 am

    An easy way around this is to let your PHP script return something like:

    callback_function(YOUR_DATA);
    

    Then in the JS script included on the clients site you dynamically insert a <script> which has src pointing to your PHP script:

    (function() {
        var scriptElement   = document.createElement('script');
        scriptElement.type  = 'text/javascript';
        scriptElement.async = true;
        scriptElement.src   = 'http://example.org/yourScript.php?data=...';
        var container       = document.getElementsByTagName('script')[0];
        container.parentNode.insertBefore(scriptElement, container);
    })();
    

    This technique is called JSONP and should do exactly what you want 😉

    Another way around the problem would be allowing cross-domain XMLHttpRequest in the Content Security Policy. But I think only Firefox 4 supports that right now.

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

Sidebar

Related Questions

I know this question is overly popular, but I find nothing that addresses rewriting
I know that this has already been asked here but the answer (using a
I know this is a popular topic, but I've been searching quite a bit
I know that this sort of question has been asked here before, but still
I know that this is a newbie question but I am a newbie so
I know that this feature will be deprecated in C++0x, but for me as
I'm trying to record sound using Android Emulator. I know that this question is
I know that this line of code will make the cell text-wrap: $objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true); 'D1'
I know that this question must have been asked and answered a million times,
I know that this question had already been asked a couple of times before,

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.