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