$. Get, $. post, $. getJSON, and $. ajax methods in jQuery

Source: Internet
Author: User

JQuery. get ()

JQuery. ajax (): executes asynchronous HTTP (Ajax) requests.



$ (Selector). get (url, data, success (response, status, xhr), dataType)


The simple GET request function replaces the complex $. ajax. You can call the callback function when the request is successful. To execute a function when an error occurs, use $. ajax.

Example:

$. Get ("product? Type = 111 ", {id: '000000', name: 'qingteng Garden ',}, function (data, state) {// The returned data alert (data) is displayed here; // The returned status alert (state );})


$.ajax({  url: url,  data: data,  success: success,  dataType: dataType});


The post () method loads data from the server through an http post request

This method is similar to $. get (), but only one type parameter is added. Here we will only introduce the type parameter. For more information, see $. get () above.

Type: type indicates the request data type, which can be html, xml, json, and Other types. If we set this parameter to json, the returned format is json, and $. the format returned by get () is the same as that returned by get.

JQuery. post (url, data, success (data, textStatus, jqXHR), dataType)


$.ajax({  type: 'POST',  url: url,  data: data,  success: success,  dataType: dataType});
$. Post ("product? Type = 111 ", {id: '000000', name: 'qingteng Garden ',}, function (data, state) {// The returned data alert (data) is displayed here; // The returned status alert (state) ;}, "json ")


JQuery. getJSON (url, data, success (data, status, xhr ))


$.ajax({  url: url,  data: data,  success: callback,  dataType: json});

$.getJSON("test.js", function(json){  alert("JSON Data: " + json.users[3].name);});



All options can be set globally using the $. ajaxSetup () function.

JQuery. ajax ([settings])


// JQuery code: $ (document ). ready (function () {$ ("# b01 "). click (function () {htmlobj = $. ajax ({url: "/jquery/test1.txt", async: false}); $ ("# myDiv" ).html (htmlobj. responseText );});});
// HTML code: <div id = "myDiv"> 

    -The key/value data sent to the server from the specified resource request data will be appended to the request URL as QueryString. The format of the data returned by the server is actually a string, it is not the json data format we want
  • -Submit the data to be processed to the specified resource. the get () parameter is similar. A type parameter is added, and the type is the returned data type, which can be html, xml, json, and Other types. If we set this parameter to json, the returned format is in json format. If no value is set, it is equal to $. get () returns the same format as a string.









Related Article

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: [email protected] 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.