Trying out Ajax JSON for the first time has been a bit tricky. Even though I hard coded "Record: 1" on the server side, it keeps alerting me with a total record of 0. I'm not sure where I went wrong. Could it be an issue with how I passed the array data? Strangely, no error messages are showing up. Any help would be appreciated. Thanks.
$.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);
}
});
server side:
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 &"""}}"
I found a solution by changing the method from GET to 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);
}
});