如何通过 jQuery 执行以下操作?
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementByID('statusDisplay').innerHTML = xmlhttp.responseText; // show loaded content
} else if (xmlhttp.readyState >= 1 && xmlhttp.status == 200) /* if(xmlhttp.readyState>=2 && xmlhttp.status==200) */ {
document.getElementByID('statusDisplay').innerHTML = '<img src="ajax_load.gif" />'; // show ajax loading image
}
}
xmlhttp.open("GET", "path/to/file.php", true);
xmlhttp.send();
我主要感兴趣的是如何检索 readyStatea 和状态,以及如何从这些函数中检索响应文本(或多或少像这样):
$.ajax({url: 'path/to/file.php', async: true, success: function(){
// how can I get the responseText here?
}, whileLoading: function(){
// does such a parameter actually exist?
}});
提前致谢!