Jquery .ajax获取请求总是失败

Jam*_*mes 1 jquery json http

除了失败之外我无法做出此要求.我使用curl和web开发人员工具栏来检查创建的URL,WD总是说响应正确地返回200.我已经尝试将内容类型更改为text,octet-stream并将其注释掉.我还采用了JSON响应并使用JSONLint对其进行了验证.

我正在使用的代码就是这个;

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <link rel="stylesheet" type="text/css" href="css/testing.css">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
    <script type="text/javascript">
    $(function(){
        $("body").append("<p>Testing.....</p>");
        var test= {latitude:"37.0205",longitude:"-7.969141667",startDate:"09-01-2014",endDate:"09-02-2014"};
        var url="<hidden>";

        $.ajax({
            url : url,
            type: "GET",
            data : test,
            dataType:"json",
            contentType:"application/json",
            success: function(data,status)
            {
                $("body").append("<p>Success"+JSON.stringify(data)+"</p>");
                $("body").append("<p>Success"+status+"</p>");
            },
            error: function (jqXhr,textStatus,errorThrown)
            {
                $("body").append("<p>Failure " + JSON.stringify(jqXhr)+"----- "+ textStatus+ "----- "+ errorThrown+"</p>");
            }
        });
        $("body").append("<p>input"+JSON.stringify(test)+"</p>");
    });
    </script>
</head>
<body>
    <h1>Weather test</h1>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我在Web浏览器中从错误函数输出的是"Failure {"readyState":0,"responseText":"","status":0,"statusText":"error"} -----错误--- - "

标题是形式,

HTTP/1.1 200 OK Cache-Control:private,max-age = 0服务器:Microsoft-IIS/7.5 X-AspNet-Version:4.0.30319 X-Powered-By:ASP.NET日期:星期五,2014年10月3日11: 57:47 GMT内容长度:25328

并使用curl -ivs --raw获取所有适当的get参数的url.在此之后直接跟随有效的JSON.我担心没有内容类型可能会抛出这个.

我知道还有很多其他类似的问题,但我先尝试通过它们并应用所学到的经验教训.如果您有任何其他建议,我将非常感激.

谢谢,

Bog*_*rym 7

正如你写的, I'm running the web-page on a server on my home machine and the url is for a different, external server not under my control.

它通常意味着同源策略规则在此处起作用.

它不允许您发送跨域ajax请求这么容易.

如果您确实需要发送跨域ajax请求,请查看JSONPCORS.