xmlHttp.status==200从来都不是真的
xmlHttp.status==200 is never true
我有一个项目,我正在使用ajax和php。问题是XMLHttpRequest()的状态永远不会是200。我搜索的解决方案都不起作用,所以我在这里询问。我在这里复制/粘贴ajax发送变量的脚本和php文件。脚本
function categoryfilter(int) {
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 $$ xmlHttp.status == 200) {
document.getElementById("test").innerHTML = xmlHttp.responseText;
alert("GOOD");
}
}
xmlHttp.open("GET","ajax_livecategorysearch.php?category=" + int, true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.send();
}
php文件
<?php echo "whatever"; ?>
html代码
<input id="category" name="category" type="radio" checked="checked" onclick="categoryfilter(this.value);" >
当我删除条件xmlHttp.status==200时,函数返回错误404找不到页面。
您在代码中有一个拼写错误:
if (xmlHttp.readyState==4 $$ xmlHttp.status==200)
应该是
if (xmlHttp.readyState==4 && xmlHttp.status==200)
相关文章:
- 指令加载真的很长,检查加载时间的方法
- JS,“;对象”;,这个和那个.来自蟒蛇这真的让我很困惑.(双关语)
- 为什么这是真的:parseInt(1111111111111,2)===parseInt(111111111111,2)
- (false==false==true)怎么可能是真的
- 使用js/jQuery检查对象(而不是元素)是否真的存在
- 为什么typeof的数组的数组的未定义值返回为“0”;未定义的“;我的条件不认为是真的
- coffescript/javascript函数数组的行为真的很奇怪
- Passport.js`isAuthenticated()`不一致的行为;当它应该是真的时候是假的
- 真的没有办法在Firefox中自动杀死没有响应的脚本吗
- html() 真的取代了 html 代码吗?
- 在 Meteor.loginWithPassword 之后,旧用户不会离线(meteor-user-status 包)
- 有没有办法检测用户是否真的远离计算机
- 饶恕是真的就是假的
- Extjs form.reset() 不作为 trackResetOnLoad 工作是真的
- 在 JavaScript 中真的需要提升以实现相互递归吗?
- 为什么 1.2 == true 返回 false 如果布尔值 (1.2) 实际上是真的
- IE11真的与getNamedItem()JS函数不兼容吗
- GWT应用程序中出现错误HTTP 404(“Script Tag Failure-no status available
- Spring MVC中的PUT方法HTTP Status 400-AngularJS
- xmlHttp.status==200从来都不是真的