jquery Ajax application return type is HTML JSON

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.