weixin_33713350 2009-11-25 07:15 采纳率: 0%
浏览 115

jQuery Ajax在不同的端口上

My php file located at port 80 (default port) while my ajax call are on port 8080.

My index.html on port 8080

$(document).ready(function(){
$.get("userCheck.php", 
        {"username" : "lazy", "favcolor" : "FFFFFF" },          
        function(data){ alert("Data Loaded: " + data);
});

My PHP

$user = $_GET["username"];
if($user == "lazy")
    echo "SUCESS";
else
    echo "FAIL";

I have googled abit, JSONP came out mostly. Any idea how to convert it to JSONP?

Any way to make it work?

  • 写回答

6条回答 默认 最新

  • weixin_33688840 2009-11-25 07:17
    关注

    you cannot do that because of the same origin policy. Since the port are different the same origin policy would apply and block your XHR call.

    You would have to use a proxy to do such things, you can take a look at JsonP or build your own proxy using curl or copy your code to be on the same port.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料