标签:php javascript jscript
function ajaxGet(url, obj) {
var request;
if(window.XMLHttpRequest) {
request = new XMLHttpRequest();
} else {
request = new ActiveXObject(‘Microsoft.XMLHTTP‘); // 兼容IE
}
request.onreadystatechange = function() {
if(request.readyState === 4) { // 4 请求完成
if(request.status === 200) { // 200 页面成功加载
console.log(request.responseText); // 成功 返回得到的文本
} else {
console.log(request.status); // 失败 返回状态码 如 404
}
} else {
console.log(‘Requesting‘);
}
}
/* 解析参数 */
str = ‘?‘;
for(key in obj) {
str += (key + ‘=‘ + obj[key] + ‘&‘);
}
str = str.substr(0, str.length - 1);
/* 发送 */
request.open(‘GET‘, url + str);
request.send();
}
ajaxGet(‘ajax.php‘, {
‘type‘: ‘get‘,
‘data‘: ‘test‘
}); //get-test<!-- ajax.php --> <?php echo $_GET[‘type‘] . ‘-‘ . $_GET[‘data‘];
本文出自 “不知不问” 博客,请务必保留此出处http://mazey.blog.51cto.com/12997993/1975314
标签:php javascript jscript
原文地址:http://mazey.blog.51cto.com/12997993/1975314