这是我第一次尝试ajax json。它一直显示我从服务器端的总记录是0,虽然我在服务器端硬编码记录:1仍然警告我记录与0.我很想知道我在哪里做错了。从我传递的数组数据的方式是错误的吗?但是没有显示任何错误消息。感谢。
$.ajax({
url: "CL0022_CHECK_GL_INDICATOR.asp",
method: "GET",
dataType: "json",
data: { 'arrGL':array.join('+++')},
success: function (data) {
alert(data.detail.Record)
for(var i = 0; i < data.detail.Record; i++){
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
服务器端:
arrGL = Split(Request.Form("arrGL"),"+++")
arrLength = UBound(arrGL) + 1
Response.Write "{""detail"": {"
Response.Write """fields"": ["
For Each x In arrGL
intcount = intcount + 1
If intcount Mod 2 <> 0 Then
intcount2 = intcount2 + 1
resetRst
strSQL = " Select * from FLP003 Where ACCN='" & replace(x,"'","''") & "'"
objRst.Open StrSQL,objConn
If objRst.recordCount > 0 Then
Response.Write "{""PSTIN"": """& trim(objRst.Fields("PSTIN"))&""","
Response.Write """FSTAG"": """&trim(objRst.Fields("FSTAG"))&""","
Response.Write """RECACI"": """&trim(objRst.Fields("RECACI"))&""","
Else
Response.Write "{""PSTIN"":"""","
Response.Write """FSTAG"": """","
Response.Write """RECACI"": """","
End If
Else
Response.Write """LINE"": """& x &"""}"
If arrLength <> intcount Then
Response.Write ","
End If
End If
Next
Response.Write "],"
Response.Write """Record"": """& intcount2 &"""}}"
我找到了解决方案,只是将方法从GET更改为POST。
$.ajax({
url: "CL0022_CHECK_GL_INDICATOR.asp",
method: "POST",
dataType: "json",
data: { 'arrGL':array.join('+++')},
success: function (data) {
error: function (jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
答案 0 :(得分:0)
您需要在提醒之前使用var obj = JSON.parse(data);
。试着希望它会帮助你。并尝试这个alert(data.detail.Record.length);
更新2
尝试使用此
$.each(data.detail.fields,function(i){
console.log(data.detail.fields[i].PSTIN);
});
尝试使用
jQuery.each()
它可以帮助您。