Home > Web Front-end > JS Tutorial > body text

Use of native ajax variable parameter post (code example)

青灯夜游
Release: 2018-10-23 17:42:24
forward
2929 people have browsed it

The content of this article is to introduce the use of native ajax variable parameter post (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

var Ajax = {
post:function(){
xmlhttp = new XMLHttpRequest();var len = arguments.length;var url = arguments[0];
callback = arguments[len-1];var str = '';
xmlhttp.open('POST', url, true);
xmlhttp.onreadystatechange=function()
{if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
callback(xmlhttp.responseText);
}
}if (len = 3) {
data = arguments[1]for(i in data){
str += i + "=" + data[i] +"&"}
str = str.replace(/&$/gi,'')
}if (len = 4) {
headers = arguments[2]for(i in headers){
xmlhttp.setRequestHeader(i,headers[i])
}
}
xmlhttp.send(str);
}
}
Copy after login

Basic syntax of variable parameter post:

Ajax.post(url,{},header,function(){
})
Copy after login

The first parameter is the url, the second is the data parameter, the third parameter is the header, and the fourth is the return function

The above is the detailed content of Use of native ajax variable parameter post (code example). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template