Bạn tạo 1 file test.php như sau:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Ajax testing!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" language="javascript">
var httpRequest = false; //Ban đầu chưa có request
function makeRequest(url) {
httpRequest = false;
if (window.XMLHttpRequest) { // Kiểm tra hỗ trợ đối tượng XMLHttpRequest trên Mozilla, Safari,...
httpRequest = new XMLHttpRequest();
if (httpRequest.overrideMimeType) {
httpRequest.overrideMimeType(text/xml);
}
} else
if (window.ActiveXObject) { // Trên IE, kiểm tra xem ActiveX có bị disable
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
//Xử lý khác của bạn
alert(e.toString());
}
}
}
if (!httpRequest) {
alert("Giving up : Cannot create an XMLHTTP instance");
return false;
}
httpRequest.onreadystatechange = alertContents;
httpRequest.open("POST",url, true);
httpRequest.send("bb=bbbs");
}
Read the rest of this entry »