weixin_33743661 2015-07-03 15:10 采纳率: 0%
浏览 4

Ajax发布不起作用

I'm new in ajax and try to get data from a post request. This is my code:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>
$(document).ready(function(){

    $("button").click(function(){

  $.post("10.0.0.10/info/page.php",
        {
          id: "1234"
        },
        function(data,status){
            alert("succesData: " + data + "
Status: " + status);
        })  
        .fail(function(data,status) {
            alert("failData: " + data + "
Status: " + status);
  });
    }); 
    });
</script>

</head>
<body>
<input id="id" type="text">
<button>Change Content</button>
</body>
</html>

I just try page.php page with html form and get this json:

[{"cabin_id":"1234","city":"","type":"","year":"2009"}]

So 10.0.0.10/info/page.php working fine but my ajax code can't get data. I only get .fail alert box and it says:

alert box

What is wrong on my ajax code?

EDIT:

I see this error now:

XMLHttpRequest cannot load file:///C:/Users/KUVALYA/Desktop/post. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
  • 写回答

2条回答 默认 最新

  • weixin_33749242 2015-07-03 15:12
    关注

    If you don't specify the scheme (e.g. https://) or start the URL with // (indicating that it is relative to the current scheme) then the first part will be treated as a directory, not a hostname.

    You are requesting something like: http://example.com/foo/10.0.0.10/info/page.php.

    Correct your URL.

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码