开发者

jQuery .load() post issue

开发者 https://www.devze.com 2023-02-27 20:52 出处:网络
This code is working perfectly: $(document).ready(function() { $(\"#submit\").click(function(){ $(\"#output\").load(\"extract.php\", {query: $(\"#input\").val()} );

This code is working perfectly:

$(document).ready(function() {
  $("#submit").click(function(){
    $("#output").load("extract.php", {query: $("#input").val()} );
  });
});

However, when I change the link from extra开发者_StackOverflow社区ct.php to the same exact file on an external server, the script stops working:

$(document).ready(function() {
  $("#submit").click(function(){
    $("#output").load("http://example.com/extract.php", {query: $("#input").val()} );
  });
});

According to firebug, the latter script is posting to the external file, but there is no response for some reason. Any thoughts? Greatly appreciate it.


To quote @Rocket:

You cannot sent POST requests to an external server, it's called the Same Origin Policy.

What you can, however, do, is use some server-side code (such as PHP) hosted locally to make that POST request for you. Here is one such post describing one way to do it: jQuery AJAX Proxy (with POST data) in PHP

0

精彩评论

暂无评论...
验证码 换一张
取 消