Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to perform a simple jQuery AJAX attempt using either a .get() or a .post().

If I have a local copy on my server and do:

$.get('/hash.php',...,...)

I monitor in my console in firebug that the get is done and I get a response.

All I change is the URI to an outside server and nothing happens.

$.get('https://secure.mysite.com/subdir/hash.php',...,...)

Doesn't help if I take the 's' off or if I use post instead. Am I missing some parameter that I should use in jQuery?

EDIT: I forgot to mention the reason I'm doing this is because I am eventually migrating from a PHP4 site to a PHP5 site, but for now the live PHP4 site needs a function that isn't in PHP4. So I am calling a PHP5 server to do it. I think I have a good workaround. Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
298 views
Welcome To Ask or Share your Answers For Others

1 Answer

You cannot send an Ajax Request to another domain than the other on which your application is deployed. This is because of the Same Origin Policy implemented in web-browers -- a security measure.

There are two possible solutions, though :

  • sending the request to your own server, that will act as a proxy to another (either via a PHP script, or, better, using some of Apache's mod_proxy_http module)
  • or not using "Ajax", but other techniques, like dynamically creating <script> tags -- which are not subject to the SOP constraint.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...