JQuery AJAX and jqueryajax

Source: Internet
Author: User

JQuery AJAX and jqueryajax

  

I. Why JQuery AJAX?

  • Because in the Development of AJAX in traditional (js), AJAX has two main problems:
  • For browser compatibility issues, writing AJAX code is too troublesome and many of them are the same.
  • In actual development, Ajax is usually used by jQuery ajax.
Ii. Ajax APIs of JQuery
    • $. Get (path, [Request Parameter], [callback function], [data type]); Data Type: string by default

    • $. Post (path, [Request Parameter], callback function, [data type]); Data Type: string by default

    • $. GetJSON (url, request parameter, callback function) Application Scenario: when the data returned by the server to the client is of the json type

    • Data Type (dataType): "xml ",

      "Html ",

      "Text ",

      "Script ",

      "Json ",

      "Jsonp"

3. Getting Started

  • Get Method
$ ("# Btn1 "). click (function () {// send the request; $. get (url, [params], [function (result) {}]) $. get ("$ {pageContext. request. contextPath}/demo01 ",
{"Username": "zs", "password": "123456 "},
Function (result) {alert (result );});});
  • Post method
$ ("# Btn2 "). click (function () {// send the request; $. post (url, [params], [function (result) {}]) $. post ("$ {pageContext. request. contextPath}/demo01 ",
{"Username": "zs", "password": "123456 "},
Function (result) {alert (result );});});
  • GetJSON Method
// From test. js loads JSON data and attaches parameters to display a name field in JSON data. // $. jQuery. getJSON (url, [data], [function (result) {}]) $. getJSON ("test. js ", {name:" John ", time:" 2 "}, function (json) {alert (" JSON Data: "+ json. users [3]. name );});

 

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: 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.