In the jQuery 1.2 , you can load JSON data across domains and use it to set the data type to JSONP. When calling a function using JSONP form, such as "myurl?callback=?" JQuery is automatically replaced ? To the correct function name to execute the callback function. When the data type is set to "Jsonp" , jQuery automatically invokes the callback function.
Name of parameter
|
Type
|
Describe
|
URL
|
String
|
( default : current page address ) the address where the request was sent.
|
type
|
String
|
( default : "Get") Request Method ("POST" or "get") , Default to "Get" . Note: Other HTTP request methods, such as put and DELETE , are also available, but only partially supported by browsers.
|
Timeout
|
Number
|
Sets the request timeout (in milliseconds). This setting overrides the global setting.
|
Async
|
Boolean
|
( default : TRUE) all requests are asynchronous requests under the default settings. If you need to send a sync request, set this option to false . Note that the synchronization request will lock the browser and the user's other actions must wait for the request to complete before it can be executed.
|
Beforesend
|
Function
|
can be modified before sending a request XMLHttpRequest object functions, such as adding custom HTTP headers. The XMLHttpRequest object is the only parameter.
function (XMLHttpRequest) {
This The options for this AJAX request
}
|
Cache
|
Boolean
|
( default : TRUE) jQuery 1.2 new functionality, set to false to not load request information from the browser cache.
|
Complete
|
Function
|
callback function after request completes ( called when the request succeeds or fails ) . Parameters:XMLHttpRequest Object, Success message string.
function (XMLHttpRequest, textstatus) {
This The options for this AJAX request
}
|
ContentType
|
String
|
( default : "application/x-www-form-urlencoded") content encoding type when sending information to the server. Default values are appropriate for most applications.
|
Data
|
Object,
String
|
data sent to the server. is automatically converted to the request string format. The GET request is appended to the URL . View The ProcessData option description to prevent this automatic conversion. Must be in the key/value format. If you are an array,JQuery will automatically correspond to the same name for different values. such as {foo:["bar1", "Bar2"]} is converted to ' &foo=bar1&foo=bar2 ' .
|
DataType
|
String
|
expects the server to return. If not specified, jquery automatically returns based on the HTTP package mime Information responsexml or responsetext and passed as a callback function parameter, available values :
"xml": returns a XML document that can be processed with jQuery .
HTML: returns plain text HTML information; contains script element. The
script: returns the plain text JavaScript code. Results are not automatically cached.
JSON: returns JSON data .
"Jsonp": jsonp format. When calling functions using jsonp , such as "myurl?callback=?" jquery The automatically replaces ? as the correct function name to execute the callback function.
|
error
|
Function |
( default : automatically determines that the (xml or html)) request fails. This method has three parameters: the xmlhttprequest object, the error message, and (possibly) the error object being caught.
function (XMLHttpRequest, textstatus, Errorthrown) {
/ /&NBSP typically textstatus and Errorthown have only one of the values
span> this; The options for this Ajax request
}
|
Global
|
Boolean
|
( default : TRUE) whether to trigger the global AJAX events. setting to false will not trigger global AJAX events, such as Ajaxstart or ajaxstop . Can be used to control different Ajax events
|
Ifmodified
|
Boolean
|
( default : false) gets new data only when the server data changes. Use HTTP packet last-modified header information to determine.
|
processdata
|
( default : TRUE) &n Bsp By default, the data sent is converted to an object ( technically not a string ) to match the default content type "application/x-www-form-urlencoded" . If you want to send DOM tree Information or other information that you do not want to convert, set to false .
|
success
|
function
|
callback function after successful request. This method has two parameters: the server returns data, returns the status
function (data, textstatus) {
// Data could be xmldoc, jsonobj, HTML, text, etc ...
this;//The options for this Ajax request
}
|
Here are a few Ajax Event Parameters:
beforesend ,
success ,
complete, error. We can define these events to deal well with each of our Ajax requests. Notice that this in these Ajax events is the information about the options for the Ajax request (refer to the Get () A picture of this at the time of the method .
Read the argument list carefully, and if you want to use jQuery for Ajax development, you need to be familiar with these parameters.
1. Request page ajax.asp Tutorial x
<div>
<input id= "txtname" type= "text"/><input type= "button" value= "to see if the username exists" id= "btn" onclick= "Judgeusername ();" />
<div id= "Showresult" style= "Float:left" >div>
div>
<script type= "text/web Effects" src= "Css/jquery-1.3.2.js" ></script>
<script type= "Text/javascript" >
function Judgeusername ()
{
$.ajax ({
Type: "Get",
URL: "Ajaxuserinfomodify.aspx",
DataType: "HTML",
Data: "Username=" +$ ("#txtName"). Val (),
Beforesend:function (XMLHttpRequest)
{
$ ("#showResult"). Text ("Query Now");
Pause (this,100000);
},
Success:function (msg)
{
$ ("#showResult"). HTML (msg);
$ ("#showResult"). CSS Tutorial ("Color", "red");
},
Complete:function (Xmlhttprequest,textstatus)
{
Hide query Picture
},
Error:function ()
{
Error handling
}
});
}
</script>
2 , page ajaxuserinfomodify.aspx
protected void Page_Load (object sender, EventArgs e)
{
String userName = request.querystring["UserName"]. ToString ();
if (UserName = "James Hao")
{
Response.Write ("User name already exists!") ");
}
Else
{
Response.Write ("You can use this username!") ");
}
}
(1) Initialization interface
(3) Verify that the user name already exists on the page
(4) Verify that the user name does not exist on the page
The ability to verify that the user name exists has been completed by Ajax.