Home >Web Front-end >JS Tutorial >Use of native ajax variable parameter post (code example)

Use of native ajax variable parameter post (code example)

青灯夜游
青灯夜游forward
2018-10-23 17:42:242958browse

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);
}
}

Basic syntax of variable parameter post:

Ajax.post(url,{},header,function(){
})

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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete

Related articles

See more