我正在尝试从 ASP 页面(我在其中创建动态 javascript 数组)获得响应。但是在 AJAX 回调之后,我无法访问 javascript 数组。
我已经阅读了 stackoverflow 文章调用从 Ajax 响应返回的 JavaScript 函数,它解决了与我的问题类似的问题。
不知道这有什么问题。我在下面简要介绍我编写的代码。
Function ()
{
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 1) {
alert('connection');
}
if (xmlhttp.readyState == 3) {
alert('processing');
}
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
alert('back with the bang');
document.getElementById('dvCallback').innerHTML = xmlhttp.responseText;
eval(document.getElementsByID("runscript").innerHTML);
split1 = arrJSCalT[i].split(":");
alert(split1[1]);
}
}
xmlhttp.open("POST", "Sys_Add.asp", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send();
return false;
}
Sys_Add.asp 如下。
<%
response.Expires = -1
dim strErrMsg
recCntr = 0
recCntr = rsCalT.RecordCount
recCntr = recCntr - 1
dim dicCalT
set dicCalT = CreateObject("Scripting.Dictionary")
if rsCalT.RecordCount <> 0 then
rsCalT.MoveFirst
do while not rsCalT.EOF
dicCalT.Add cstr(rsCalT(0)), cstr(rsCalT(1))
rsCalT.MoveNext
loop
end if
Call FillJSArray(dicCalT,"arrJSCalT")
Sub FillJSArray(dicVB, arrJS)
dim itr
a = dicVB.keys
b = dicVB.items
Response.write ("<script language=""javascript"" id=""runscript"" name =""runscript"">" & VbCrLf )
Response.Write ("var " & arrJS & "= new Array(" )
for i = 0 To dicVB.Count - 1
If i > 0 then
response.write (",")
End If
Response.Write ("""" & a(i) & ":" & b(i) & """")
Next
Response.Write (");" & vbCrLf )
'Response.write "alert(""running from main"");"
Response.write ("</script>" & VbCrLf)
Response.write ("so this is printed as welll")
End Sub
'END creating javascript array from asp recordset
response.Write ("Did you want this??")
%>
我在 split1 = arrJSCalT[i].split(":"); 行出现错误 如果我能得到这方面的帮助,我将不胜感激。
谢谢...普拉尚特....