请教各位大侠 如何使用httpclient发送 AJAX请求
答案:1 悬赏:80 手机版
解决时间 2021-12-29 06:47
- 提问者网友:眉目添风霜
- 2021-12-28 15:03
请教各位大侠 如何使用httpclient发送 AJAX请求
最佳答案
- 五星知识达人网友:污到你湿
- 2021-12-28 16:18
示例:
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);
}
});
}
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);
}
});
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯