Using jquery's AJAX functionality to invoke a page, you find that there is always an error.
JS code is as follows
Copy Code code as follows:
$.ajax ({
Type: ' Post ',
URL: ' testdata.aspx ',
Data: {
Language_type: ' CN '},
DataType: ' JSON ',
Success:function (data) {
Alert (' OK ');
},
Error:function (data) {
Alert (' Err ');
});
}
The testdata.aspx code is as follows, omitting some of the code behind
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "TestData.aspx.cs" inherits= "Demand_testdata"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
The TestData.aspx.cs code is as follows
Copy Code code as follows:
public partial class Demand_TestData:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
List<testc> t=new list<testc> ();
for (int i = 0; i < i++)
{
TESTC C = new TESTC ();
c.rd_id = i;
T.add (c);
}
String test = Jsonconvert.serializeobject (t);
Response.ContentType = "Application/json";
Response.Write (test);
Response.Clear ();
}
}
public class TESTC
{
public int rd_id
}
But just a few lines of code, jquery always complains, if the DataType: ' JSON ', modified to other types will not be wrong, very strange, but my system, what is needed is ' JSON object
Finally, after repeated tests to find that the code to modify the following places is finally normal
1 Remove the Response.Clear () from the TestData.aspx.cs page; what's not clear?
2 Modifying the class TESTC to the following form, which is to add the Read settings property to the field
Copy Code code as follows:
public class TESTC
{
private int rd_id;
public int rd_id
{
get {return rd_id;}
set {rd_id = value;}
}
}
3 Delete all the code in the Testdata.aspx page, leaving only the first line and the modified code as follows
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "TestData.aspx.cs" inherits= "Demand_testdata"%>
After so many tests, it's finally normal.
I've found that using jquery's Ajax often skips back into the wrong process, especially dataType: ' json ', it seems that jquery has a very strict validation mechanism, it looks like this must be noted, otherwise it will be wrong