jquery Ajax
Example: function Judgeusername ()
{
$.ajax ({
Type: "GET",
Http://www.cnblogs.com/Ilin631/admin/%22Default2.aspx ",
DataType: "HTML",
Data: "Username=" +$ ("#txtName"). Val (),
Beforesend:function (XMLHttpRequest)
{
$ ("#showResult"). Text ("Querying ...");
Pause (this,100000);
},
Success:function (msg)
{
$ ("#showResult"). HTML (msg);
$ ("#showResult"). CSS ("Color", "red");
},
Complete:function (Xmlhttprequest,textstatus)
{
Hide a picture being queried
},
Error:function ()
{
Error handling
}
});
}
Where error is a must, cannot but write.
Datatype:xml Script HTML JSON
HTML back in the background is placed in Response.Write ():
String userName = request.querystring["UserName"]. ToString ();
if (UserName = = "James Hao")
{
Response.Write ("User name already exists!") ");
}
Else
{
Response.Write ("You can use this user name!") ");
}
JSON: Background placed in: datatype: "JSON";
String name = context.request["UserName"];
if (name = = "AA")
{
Context.Response.Write ("1");
}
Else
{
Context.Response.Write ("0");
}
1 Judging browser support.
<script type= "Text/javascript" >
function Ajaxfunction ()
{
VarxmlHttp
;
Try
{
Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (E)
{
Internet Explorer
Try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (E)
{
Try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E)
{
Alert ("Your browser does not support ajax! ");
return false;
}
}
}
}
</script>
2 How to use the XMLHttpRequest object to communicate with the server. The three important attributes of a XMLHttpRequest object.
Xmlhttp.onreadystatechange=function ()
{
if ( xmlHttp.readyState==4
)
{
Getting data from the server's response
Document.myform.time.value= xmlHttp.responseText
;
}
}
3 requesting data from the server
To send the request to the server, we need to use the open () method and the Send () method.
The open () method requires three parameters. The first parameter defines the method (GET or POST) that is used to send the request. The second parameter specifies the URL of a server-side script. The third parameter specifies that the request should be processed asynchronously.
The Send () method can send the request to the server. If we assume that the HTML file and the ASP file are in the same directory, then the code is:
XmlHttp. open
("GET", "time.asp", true);
XmlHttp. send
(null);
Reference: http://www.w3school.com.cn/ajax/ajax_server.asp
Http://www.w3school.com.cn/aspnet/index.asp
Http://blog.csdn.net/richcem/archive/2010/05/05/5558369.aspx
jquery Ajax application return type is HTML JSON