Home  >  Article  >  Web Front-end  >  Comparison of common code implementations between JQuery and Ajax_jquery

Comparison of common code implementations between JQuery and Ajax_jquery

WBOY
WBOYOriginal
2016-05-16 18:45:26866browse

传统ajax Code

复制代码 代码如下:



JQuery方法
Code
复制代码 代码如下:




get and post
Code
复制代码 代码如下:

GET VS. POST




输入姓名和生日
















控制ajax
Code
复制代码 代码如下:

$.ajax() method




Enter name and birthday
















Global settings ajax
Code
Copy code The code is as follows:

$.ajaxSetup() method

< ;script language="javascript">
$.ajaxSetup({
//Global settings
url: "14-5.aspx",
success: function(data){
$("#serverResponse").html(decodeURI(data));
}
});
function createQueryString(){
//You must encode twice to solve the Chinese problem
var firstName = encodeURI(encodeURI($("#firstName").val()));
var birthday = encodeURI(encodeURI($("#birthday").val()));
/ /Combined into an object form
var queryString = "firstName=" firstName "&birthday=" birthday;
return queryString;
}
function doRequestUsingGET(){
$.ajax({
data: createQueryString(),
type: "GET"
});
}
function doRequestUsingPOST(){
$.ajax({
data: createQueryString() ,
type: "POST"
});
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn