jquery and Ajax

Source: Internet
Author: User
Tags getscript

$.get (): Asynchronous request with Get method

$.get (url,data/{"param1": "Pamaram1value",},callback,type)

The callback of the $.get () method has only two parameters:

function (data,textstatus) {

Data

Textstatus

}

The data parameter represents the content returned by the request, and Textstatus represents the status of the return request

Returns the XML document: When the data format returned by the server side is an XML document, the returned data needs to be processed, as is the case with XML documents and HTML documents, as well as with the regular Attri (). Find (). Fliter () and other methods, the jquery code is as follows:

$ (function () {

$ ("selector"). Click (function () {

$.get ("url", {

param1:$ ("#param1"). Val (),

param2:$ ("#param2"). Val ()

},function (data,textstatus) {

var para1=data.param1;

var para2=data.param2;

var txthtml= "<div class= ' para1 ' >" +para1+ "</div>"

},json);

})

})

$.getscript () and $.getjson ()

$ (function () {

$ ("selector"). Click (function () {

$.getscript (' Test.js ')

})

})

$.getjson (), for loading JSON files

You can iterate through the data variables in the function, or you can use iterations to build the appropriate HTML code for each item, although it can also be implemented with a traditional for loop, jquery provides a common traversal method $.each (), which can be used to traverse objects and arrays, $. The each () function differs from the each () method of the JQuery object, which is a global function that does not manipulate the jquery object, but rather takes the first as the index of the object's member or array, and the second is the corresponding variable or content

$ (function () {

$ ("selector"). Click (function (data) {

$ ("selector"). empty ();

var html= "";

$.each (Data,function (commentindex,comment) {

html+= ' <div class= "comment" >

})

})

})

jquery and Ajax

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.