【发布时间】:2023-03-06 22:22:02
【问题描述】:
我在 Firefox 31 ESR 中收到以下错误:
错误:NS_ERROR_FAILURE:
源文件:
这是来自 Internet Explorer 11 的相同内容:
SCRIPT5022:无效状态错误
这是我调用到 AJAX 函数的脚本:
ajax('post','standard/','part='+p+'&price='+q,'sequel_sub_object_key');
这是我的 AJAX 函数:
function ajax(method,url,param_id_container_pos,id_container,id_focus,sequel)
{
var methods = Array('get','head','post');
if (window.XMLHttpRequest && in_array(method,methods))
{
xhr = new XMLHttpRequest();
xhr.open(method,url,true);//Error triggers here for localhost.
if (method=='post')
{
xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xhr.send(param_id_container_pos);
}
xhr.send(null);
xhr.onreadystatechange = function()
{console.log('xhr.readyState = '+xhr.readyState);
if (xhr.readyState=='4')
{
alert('xhr.responseText = '+xhr.responseText);
}
}
}
显然 Firefox 和 IE 非常模糊认为我在 localhost 上执行跨站点脚本...?
对于我尝试传递绝对和相对路径的 URL:
document.getElementsByTagName('base')[0].href+'standard/'window.location.href'standard'
我已经查阅了几十页,其中大部分都在 Stack 上,所有问题都已关闭。
我对跨站脚本编写的意图为零。
我不更改
method。我没有使用其他协议(全是 HTTP,不是 HTTPS)。
我没有使用任何个子域。
我从不使用框架依赖或削弱我的代码。
我确实不关心 URL 必须是绝对的还是相对的,我只是需要它工作。
这是一个内网网站。
服务器和客户端都是同一台计算机。
原始 URL 格式为:
http://localhost/Client/standard/?http-query目标网址是
http://localhost/Client/standard/。Apache Access 日志显示请求通过并返回 HTTP 200。
紧跟在
open之后的alert()onreadystatechange的所有状态均未记录在控制台中。调用
ajax函数时,并非所有参数都需要设置。
我错过了什么?
【问题讨论】:
-
readyState 是一个数字,而不是一个字符串
标签: javascript ajax localhost