How do I send a cross-domain POST request via JavaScript?

后端 未结 17 2395
说谎
说谎 2020-11-21 05:06

How do I send a cross-domain POST request via JavaScript?

Notes - it shouldn\'t refresh the page, and I need to grab and parse the response afterwards.

17条回答
  •  攒了一身酷
    2020-11-21 05:48

    One more important thing to note!!! In example above it's described how to use

    $.ajax({
        type     : 'POST',
        dataType : 'json', 
        url      : 'another-remote-server',
        ...
    });
    

    JQuery 1.6 and lower has a bug with cross-domain XHR. According to Firebug no requests except OPTIONS were sent. No POST. At all.

    Spent 5 hours testing/tuning my code. Adding a lot of headers on the remote server (script). Without any effect. But later, I've updated JQuery lib to 1.6.4, and everything works like a charm.

提交回复
热议问题