更改路径类型会导致ajax失败?

时间:2014-01-12 18:20:52

标签: javascript

我发现这很奇怪,但我最近改变了所有路径,从相对到绝对。

我看到ajax似乎在控制台中工作正常,因为我可以看到成功检索到的文件,状态为200.

这是一张照片:(它很小,但希望你可以看出状态200)

enter image description here

但是,我的回调函数停止运行,这里是代码:

if (config_ajax.type === 'get') {
    xhr = new win.XMLHttpRequest();
    xhr.open('GET', config_ajax.url, true);
    xhr.onload = function () {
        if (this.status === 200) {
            $A.log('succeeded with status 200'); // never gets here
            config_ajax.callback(xhr.responseText);
        }
    };
    xhr.send(null);
}

2 个答案:

答案 0 :(得分:0)

如果页面位于arcmarks.com,则无法向www.arcmarks.com发出AJAX请求 - 浏览器强制执行称为同源策略的内容,这会阻止您将AJAX请求发送到除原始页面之外的任何域来自。

此外,关于发送到www.www.arcmarks.com的请求的评论是正确的 - 因为代码在当前URL中添加了“www”,如果您的URL中已有www,则它将被重复。但我认为这是故意的。

答案 1 :(得分:0)

您的服务器请求格式不正确,如firebug所示

http://www.arcmarks.com/http://www.arcmarks.com/arcmarks/source/class.CMachine.php

请注意http://www显示两次