Why do I have differences with AJAX hosted local vs remote?

125 views Asked by At

I guess part of my answer relates to "same-origin" but I'm not still not absolutely clear on when it applies and when not (or why it works in one instance, but is not a solution in other cases).

I am using latest jQuery, jQuery mobile and Apache/MySQL/PHP stacks. Client is either Windows 7/Firefox 38, or iPad/PhoneGap.

My AWS hosted php code serves the following to help resolve "same origin":

$http_origin = $_SERVER['HTTP_ORIGIN'];
header("Access-Control-Allow-Origin: $http_origin");

The Phone Gap version of my app works as expected, retrieving data from my AWS server and rendering the data it has retrieved.

Calling the exact same code from my laptop browser fails. Why?

If I copy/paste the AJAX URL into my browser, it correctly pulls the JSON data from AWS.

In an effort to resolve, I dump output to console.log. The jQuery AJAX "error" section gets called instead of the "success" portion. The same "error" result occurs if I call the index.html file (which calls JS) using File Open within Firefox, or if I call the locally apache hosted index.html file, jQuery ajax jumps to "error" section.

So if my phonegap app works, but my laptop does not, why? I mean, I see my app being akin to the laptop web browser. They both in effect have a different origin than my web server so I would expect either both work, or both fail.

If someone can help clarify it would be great - I have twice spent time chasing a problem that only exists in my dev environment but works just fine in production - its frustrating!

Thanks all in advance

1

There are 1 answers

2
3pic On BEST ANSWER

Have you white listed domain in your phonegap config ? http://docs.phonegap.com/en/4.0.0/guide_appdev_whitelist_index.md.html

ex:

Access to google.com:

<access origin="http://google.com" />

__ reading it should improve : https://github.com/phonegap/phonegap-app-developer/issues/169 __