JQuery external Ajax call not working in IE

后端 未结 7 2067
梦毁少年i
梦毁少年i 2020-12-21 21:37

I have an ajax script that sends some data to an external URL. The external URL is hosted on the same server, however the domain is different than the source of the ajax cal

相关标签:
7条回答
  • 2020-12-21 22:01

    I dont think it should work on Chrome or Firefox, unless you testing on localhost or something like that, this would be against the crossdomain policy.

    What you need is to proxy it inside the same domain, use php to connect to the destination you need and call the url from the same domain.

    save_cross_domain.php -> connect through server to the desired url

    then ajax calls save_cross_domain.php

    0 讨论(0)
  • 2020-12-21 22:05

    A couple of things:

    • The answers/conversation for this question has gone a bit out of context. Actually from the question it was more implied how to make ajax calls in IE. [Atleast modify the question title, else the question is very localized]

    A couple of solutions to this cross-domain issue:

    1. CORS[compatible after IE7]
    2. JSONP [ here actually the browser takes in the input thinking it is a script]
    3. server side encoding
    0 讨论(0)
  • 2020-12-21 22:12

    http://en.wikipedia.org/wiki/Same_origin_policy

    0 讨论(0)
  • 2020-12-21 22:14

    I'm surprised any of them are working. Browsers generally don't allow ajax calls to a domain other than the one the current page came from.

    The main exception to this rule is if you make an ajax call using jsonp (json with padding). You can do this with jQuery, here's how. Look under the dataType option.

    0 讨论(0)
  • 2020-12-21 22:19

    From jQuery documentation

    Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.

    and Same Origin Policy on Wiki

    0 讨论(0)
  • 2020-12-21 22:19

    you should add a

    callback=?
    

    to your url and handle this on the server side.

    I did this once for a java servlet, and when the callback param was included I added an extra pair of parenteses around the json response..

    hope it helps!

    0 讨论(0)
提交回复
热议问题