Jquery-Ajax learning Summary

Source: Internet
Author: User

After the project started for a few days, I used self-taught jquery in the project, but I am not familiar with jquery's Ajax method because it is implemented based on httprequest, we also feel that the plug-in ajaxpro can better implement Ajax asynchronous calls. ajaxpro can directly transmit datatable, ilist, and other objects to Facilitate the Implementation of functions.

 

However, I found a problem yesterday afternoon. in IE, when jquery and ajaxpro are used at the same time, a bug occurs. As long as the ajaxpro page is registered, the jquery event will report an error, I tested it many times, and the problem was found in the core of ajaxpro. in the ashx file, I found a lot of information online without any results, but after my tests, I decided this was a bug and their internal JS conflicts.

 

This is a JS error in the core. ashx file. The error is"The type attribute cannot be obtained. Invalid parameter"Or"The object does not support this operation"

However, in Firefox, it is okay to run, but it may also be a little bit of a problem. After the button triggers the Ajax event, the button becomes a text box.

 

No way. events cannot be used in jquery, which makes me very depressed. Today, I have not done much in my project. I want to learn Ajax in jquery. I still understand the general call, for example, if datatype is XML or HTML, you can still be sloppy. Today, after reading some documents and finding good things, jquery has a good way to call the collection --JSON,I also tried this test at the beginning, but it failed because of time. Haha, I stayed at the company this evening and looked for it. That's good. Write it down first... The following is some code:

$ ("Div"). Load () method:

Code
$ ("Div"). Load ("login.html"); // load other file content to the DIV, suitable for mode Login

 

$. Get () method:

Code
$. Get ('test. aspx ', {index: 4}, function (data ){
$ ("# Result" pai.html (data );
});

 

$. Post () method:

Code
$. Post ('test. aspx ', {index: 4}, function (data ){
$ ("# Result" pai.html (data );
});

 

$. Post () method:(Get JSON)

 

Code
Ajax. ashx. CS file:

Response. contenttype = "application/JSON ";
Response. Write ("{Name: 'lidi ', age: 20 }");

Call
$. Post ("Ajax. ashx", {}, function (data ){
Alert (data. Name );
}, "Post"); // note this

 

$. Ajax () method:(Datatype: XML)

Code
$. Ajax ({
Type: "Get ",
Datatype: "XML ",
URL: "http://www.cnblogs.com/rss", // returns XML format information
Beforesend: function (XMLHttpRequest ){
$ ("IMG"). Show ();
},
Success: function (data, status ){
$ ("Div" ).html ("");
$ ("Item", data). Each (function (I, domele ){
$ ("Div"). append ("<li>" + $ (domele). Children ("title"). Text () + "</LI> ");
});
},
Complete: function (){
$ ("IMG"). Hide ();
},
Error: function (XMLHttpRequest, error ){
Alert (error );
}
});

 

 

$. Ajax () method:(Datatype: HTML)

 

Code
$. Ajax ({
Type: "Post ",
URL: "test. aspx", // returns an XML string, for example, <ul> <li> AA </LI> <li> BB </LI> </ul>
Data: "Index = 3 & name =" + $ ("# name "). val () + "& age =" + $ ("# age "). val () + "& sex =" + $ ("input: Radio: checked "). val (),
Datatype: "html ",
Timeout: 50000,
Beforesend: function (XMLHttpRequest ){
$ ("Div" pai.html (" ");
},
Success: function (XML, status ){
$ (XML). Each (function (){
$ (This). Children (). Each (function (){
$ ("<Li> </LI>" ).html ($ (this). Text (). appendto ("Div ");
});
});
},
Error: function (XMLHttpRequest, error ){
Alert (error );
},
Complete: function (){
$ ("# Imgid"). Hide ();
}
});

 

$. Ajax () method:(Datatype: script)

 

Code
$. Ajax ({
Type: "Post ",
URL: "Ajax. aspx", // The returned format is as follows: "Var A = {Name: 'lidi ', age: 20 };"
Data: "Index = 5 ",
Datatype: "script ",
Success: function (){
Alert (A. Name );
}
});

 

$. Ajax () method:(Datatype: JSON)

 

Code
$. Ajax ({
Type: "Post ",
URL: "Ajax. aspx", // The returned format is as follows: "{Name: 'lidi ', age: 20 }"
Data: "Index = 5 ",
Datatype: "JSON ",
Success: function (data ){
Alert (data. Name );
}
});

 

Hey, now I can use jquery I learned by myself. Really good!

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.