AJAX xmlHttp.readyState的返回值总是1代码如下:function QP2001_JF2001_Click(sCode,sPrtPrj,sReferFlag) {var tStrUrl;var tStrCondition;tStrCondition = " AND a.cContractCode = '" + sCode + "' "+ " AND f.cPPCode = '" + sPrtPrj + "'";tStrUrl = "
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 07:22:18
AJAX xmlHttp.readyState的返回值总是1代码如下:function QP2001_JF2001_Click(sCode,sPrtPrj,sReferFlag) {var tStrUrl;var tStrCondition;tStrCondition = " AND a.cContractCode = '" + sCode + "' "+ " AND f.cPPCode = '" + sPrtPrj + "'";tStrUrl = "
AJAX xmlHttp.readyState的返回值总是1
代码如下:
function QP2001_JF2001_Click(sCode,sPrtPrj,sReferFlag) {
var tStrUrl;
var tStrCondition;
tStrCondition = " AND a.cContractCode = '" + sCode + "' "
+ " AND f.cPPCode = '" + sPrtPrj + "'";
tStrUrl = "../qp/QP2001_A.aspx?MODE=SEARCH"
+ "&CONDITION=" + escape(tStrCondition)
+ "&SHOWMODE=" + sReferFlag
+ "&OTHER=REFER";
xmlHttp.open("GET",tStrUrl,true );
xmlHttp.onreadystatechange = QP2001_JF2001_Click_HttpResponse;
xmlHttp.send(null);
return true;
}
function QP2001_JF2001_Click_HttpResponse() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
var xmlDoc = xmlHttp.responseXML;
if (xmlDoc.documentElement) {
var tStrStatus = xmlDoc.getElementsByTagName("STATUS")[0].text;
var tStrDoc;
if (tStrStatus == "OK") {
var tIntDatanum = xmlDoc.getElementsByTagName("DATANUM")[0].text; //记录数
if (tIntDatanum == 0) {
alert("没有可操作数据.");
return false;
}else{
alert("OK");
}
}else{
alert(tStrStatus);
return false;
}
}
}
}
里面xmlHttp.readyState的返回值总是1
MaxMartin 的回答,各返回值的意义我知道,主要是不知道为啥会总返回1
服务端代码
Web.HttpContext.Current.Response.Clear()
Web.HttpContext.Current.Response.ContentType = "text/xml"
Web.HttpContext.Current.Response.AddHeader("Content-Type","text/xml; charset=utf-8")
Web.HttpContext.Current.Response.AddHeader("Cache-Control","no-cache,private")
Web.HttpContext.Current.Response.AddHeader("Pragma","no-cache")
tStrXml = "" & vbNewLine & _
"" & vbNewLine & _
" OK" & vbNewLine & _
" " & tStrMode & "" & vbNewLine & _
" JF2004" & vbNewLine & _
tStrXmlText & vbNewLine & _
""
Web.HttpContext.Current.Response.Write(tStrXml)
Web.HttpContext.Current.Response.End()
AJAX xmlHttp.readyState的返回值总是1代码如下:function QP2001_JF2001_Click(sCode,sPrtPrj,sReferFlag) {var tStrUrl;var tStrCondition;tStrCondition = " AND a.cContractCode = '" + sCode + "' "+ " AND f.cPPCode = '" + sPrtPrj + "'";tStrUrl = "
用这个ajax的封装,绝对没有问题
$ajax=function(){};
$ajax.ajax = function(ob){
if (!ob.url)
return;
var xmlhttp = (function(){
try {
return new XMLHttpRequest(); // Firefox,Opera 8.0+,Safari IE7
}
catch (e) {
if (window.ActiveXObject) {
var ActiveXName = ['MSXML2.XMLHttp.5.0','MSXML2.XMLHttp.4.0','MSXML2.XMLHttp.3.0','MSXML2.XMLHttp','Microsoft.XMLHttp'];
for (var i = 0; i < ActiveXName.length; i++) {
try {
return new ActiveXObject(ActiveXName[i]); //Internet Explorer 5.0+
}
catch (e) {
return false;
}
}
}
else {
return false;
}
}
})();
var type = ob.type || "get";
var asyn = ob.asyn || true;
if (xmlhttp) {
xmlhttp.open(type,ob.url,asyn);
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState != 4) {
//如果before在object内,就运行,否则就不运行
//一般用作loading
if (ob.before) {
ob.before();
}
}
else {
//这个success函数必须要有!
//注意,success函数传入了值进去
//或者仅仅把xmlhttp传入success也可以,然后在success的function里面写var tempText=xmlhttp.responseText 也可以的.
//或许这个以后会做修改,目前还是直接把返回的文本给success,因为这个还是很常用的
//如果新加入了一个xml,参数为true,说明传进来的是xml[这样的话就传xmlhttp,像怎样就怎样],默认是得到它的txt
ob.xml ob.success(xmlhttp) :ob.success(xmlhttp.responseText);
}
};
//这个好像可以解决IE ajax请求缓存的问题,如果不行,就把它注释吧,正在测试
xmlhttp.setRequestHeader("If-Modified-Since","0");
//xmlhttp.setRequestHeader("Cache-Control","no-cache");
xmlhttp.send(null);
}
else {
//如果error在obeject内,就运行,否则就不运行
if (ob.error) {
ob.error();
}
}
};