超级郁闷JS代码 在ASP中执行OK ASP.NET失败解决方案
超级郁闷JS代码 在ASP中执行OK ASP.NET失败
从图片中可以看出 inc目录里的Ajax.aspx文件存在 但为什么使用这段代码读取的返回结果为 404呢 很郁闷
------解决方案--------------------
当前代码在什么目录
相对目录 要相对根目录
------解决方案--------------------
你的这段JS代码在哪里?如果是在ajax.js里,然后inc文件夹下的一个页面引入了这个js文件,那么你就这样写:
- JScript code
function getHttpObject() { var objType = false; try { objType = new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { objType = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { objType = new XMLHttpRequest(); } } return objType; } function ShowIsBest(_id){ $("CD_IsBest"+_id).innerHTML= "<img src='img/star1.gif' border='0' style='cursor:pointer;margin-left:2px;' title='推荐为1星级' onclick='EditIsBest(_id,1)' /><img src='img/star1.gif' border='0' style='cursor:pointer;margin-left:2px;' title='推荐为2星级' onclick='EditIsBest(_id,2)' /><img src='img/star1.gif' border='0' style='cursor:pointer;margin-left:2px;' title='推荐为3星级' onclick='EditIsBest(_id,3)' /><img src='img/star1.gif' border='0' style='cursor:pointer;margin-left:2px;' title='推荐为4星级' onclick='EditIsBest(_id,4)' /><img src='img/star1.gif' border='0' style='cursor:pointer;margin-left:2px;' title='推荐为5星级' onclick='EditIsBest(_id,5)' />"; //$("CD_IsBest"+_id).innerHTML= '<img src="img/loading.gif" /> 读取中...'; var theHttpRequest = getHttpObject(); theHttpRequest.onreadystatechange = function () { processAJAX(); }; theHttpRequest.open("GET", "inc/Ajax.aspx?action=showisbest&id=" + _id, true); theHttpRequest.send(null); function processAJAX() { if (theHttpRequest.readyState == 4) { if (theHttpRequest.status == 200) { document.getElementById("CD_IsBest"+_id).innerHTML = unescape(theHttpRequest.responseText); } else { alert(theHttpRequest.responseText) document.getElementById("CD_IsBest"+_id).innerHTML = "异常错误"; } } } }
从图片中可以看出 inc目录里的Ajax.aspx文件存在 但为什么使用这段代码读取的返回结果为 404呢 很郁闷
------解决方案--------------------
当前代码在什么目录
相对目录 要相对根目录
------解决方案--------------------
你的这段JS代码在哪里?如果是在ajax.js里,然后inc文件夹下的一个页面引入了这个js文件,那么你就这样写:
- JScript code
function ShowIsBest(_id){ $("CD_IsBest"+_id).innerHTML= "<img src='../Img/star1.gif' //...后面省略 ... theHttpRequest.open("GET", "Ajax.aspx?action=showisbest&id=" + _id, true); theHttpRequest.send(null); //...后面省略 }
------解决方案--------------------
单独访问Ajax.aspx
------解决方案--------------------
你在vs中调试的时候,看地址栏,
在/admin/之前是http://localhost:端口号/项目名/,还是http://localhost:端口号/