[英]XMLHttpRequest's open() fails in Chrome
I am trying to patch up a bit of AJAX that doesn't work in Chrome. 我正在尝试修补一些在Chrome中无法使用的AJAX。 It's not my script and I'd rather not convert the whole thing to jQuery.
这不是我的脚本,我不想将整个内容转换为jQuery。
xmlhttp.open("GET", query, true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
console.log(xmlhttp.responseText);
}
}
xmlhttp.send();
This actually outputs something in the log while using Internet Explorer, but when in (Ch)rome I get an empty string, since the JS debugger tells me that GET
failed. 使用Internet Explorer时,这实际上会在日志中输出某些内容,但是在(Ch)rome中时,我会得到一个空字符串,因为JS调试器告诉我
GET
失败。 The target URL is correct since it works in IE, but it is some kind of ASP.NET script which inner workings I'm not very familiar with (I do the HTML, CSS and JavaScript around here). 目标URL是正确的,因为它可以在IE中使用,但是它是某种ASP.NET脚本,其内部工作方式我并不十分熟悉(我在此处使用HTML,CSS和JavaScript)。
Why could it be that IE is allowed to retrieve the information from the target, but not Chrome? 为什么会允许IE从目标而不是Chrome检索信息? When using Chrome
xmlhttp
is a XMLHttpRequest
and IE gets some kind of ActiveXObject
. 当使用Chrome时,
xmlhttp
是XMLHttpRequest
而IE获取某种ActiveXObject
。
Edit. 编辑。 I found some possible solutions here .
我在这里找到了一些可能的解决方案。
Response.Close()
, no async or specified/empty data type. Response.Close()
,没有异步或指定/空的数据类型。 It's jQuery though. 不过是jQuery。
Edit #2. 编辑#2。 What Chrome is saying about my headers.
Chrome在谈论我的标题。
Can you view the url by typing it into the address bar in Chrome? 您可以通过在Chrome浏览器的地址栏中输入网址来查看该网址吗? There could just be something about your browser config that prevents Chrome from seeing the server.
您的浏览器配置可能会阻止Chrome浏览器查看服务器。
Another possibility is that you are being scuppered by the Same Origin Policy - is the url you are accessing on the same domain as the page? 另一种可能性是您被相同来源策略所困扰-您所访问的URL与页面在同一域中吗?
Okay, so I've solved it. 好的,我已经解决了。 Chrome apparently dislikes having
Response.Close()
at the end of the requested page. Chrome显然不喜欢在请求的页面末尾添加
Response.Close()
。 Changing to Response.End()
fixed it. 更改为
Response.End()
修复了该问题。 Thank you for your help! 谢谢您的帮助!
I also replaced that JavaScript with one line of jQuery. 我还用一行jQuery替换了JavaScript。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.