The code of the aspx front-end page is as follows:
<Script language = "javascript" type = "text/javascript">
Function TestAjax (){
$. Ajax ({
Url: "www.2cto.com/", // path of the ajax request
DataType: "json ",
Data: "id = 150" + "& r =" + Math. random (), // Request Parameters
Type: "post ",
Success: function (data ){
Alert (data. name); // The name attribute value of the data object is displayed.
}
});
}
</Script>
The background. cs file is as follows:
Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
If (Request. QueryString ["id"]! = Null)
{
String id = Request. QueryString ["id"]. ToString ();
Context. Response. ContentType = "text/plain ";
// Construct json data (only one piece of data can be directly used {}. If multiple pieces of data need to be accessed using [], the foreground will be accessed using indexes) for example, jsonstr = "[{\" pricelist \ ": \" "+ temm +" \ ", \" jianye \ ": \" "+ jianye + "\", \ "sigleprice \": \ "" + oneytempprice + "\", \ "jianyetotalprice \": \ "" + jianyetotalprice + "\"}] ";
String data = "{\" id \ ": \" "+ id +" \ ", \" name \ ": \" Test content \ ", \" sigleprice \": \ "120.0 \", \ "jianyetotalprice \": \ "123.2 \"}";
Context. Response. Write (data );
Context. Response. End ();
}
}
}
Author: zcb888