请教各位大侠 如何使用httpclient发送 AJAX请求
1个回答
2016-07-19
展开全部
var http_request;
function send_request(method, url, content, callback) {
http_request = new XMLHttpRequest();
http_request.onreadystatechange = callback;
http_request.open(method, url, true);
http_request.setRequestHeader('x-requested-with', 'XMLHttpRequest');
if (method.toLowerCase() == 'post') {
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send(content);
} else {
http_request.send();
}
}
function doSend(path) {
send_request('GET', path, null, function() {
if(http_request.readyState == 4 && http_request.status == 200) {
document.write(http_request.responseText);
}
});
}
function send_request(method, url, content, callback) {
http_request = new XMLHttpRequest();
http_request.onreadystatechange = callback;
http_request.open(method, url, true);
http_request.setRequestHeader('x-requested-with', 'XMLHttpRequest');
if (method.toLowerCase() == 'post') {
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send(content);
} else {
http_request.send();
}
}
function doSend(path) {
send_request('GET', path, null, function() {
if(http_request.readyState == 4 && http_request.status == 200) {
document.write(http_request.responseText);
}
});
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询