Ajax from the beginning of the Web (vi) Ajax in jquery

Source: Internet
Author: User

Hello everyone, here is "learn the Web series from scratch" and synchronize updates at the following address ...

  • Github:https://github.com/daotin/web
  • Public number: The top of the Web front
  • Blog Park: http://www.cnblogs.com/lvonve/
  • csdn:https://blog.csdn.net/lvonve/

Here I will start with the Web front End 0 Foundation, step-up learning web-related knowledge points, during the period will also share some fun projects. Now let's go to the Web Front end learning Adventure tour!

First, the Ajax in jquery

Before we wrote so many Ajax code, in fact, is based on JS native code, in the internal JQuery, Ajax has been encapsulated, it provides a lot of methods for developers to call. However, these packages are based on a method of modification, this method is $.ajax() .

We mainly study 3 methods:

    • $.ajax ();
    • $.get ();
    • $.post ();
1, $.ajax ()

$.ajax () and his own myAjax2 () are very similar in their use, basically in accordance with the principle. Also passed in an object, some parameters are not passed, there are default values.

// 其他代码省略userObj.blur(function () {  $.ajax({    url: "./server/checkUsername.php",    type: "get",    data: {uname: this.value},    success: function (result) {      if(result == "ok") {        userSpanObj.text("用户名可用");      } else if(result == "error") {        userSpanObj.text("用户名不可用");      }    }  });});
2, $.get () and $.post

You only need to pass two parameters, the first parameter is the URL (with param, there are parameters and values), the second parameter is the callback function.

// $.get()$.get(url + "?" + params, function (result) {});// $.post()$.post(url, {参数: 值}, function(result) {});

Example:

<! DOCTYPE html>

Ajax from the beginning of the Web (vi) Ajax in jquery

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.