|
|
POST method in Ajax
I hope that you read the Ajax get method , if you don't please go through get methd.In the post method we will not pass the parameters through url. The modified 'usernameavailability' function shown here.Here we used a variable 'str' for storing parameters.Modifications are noted in red color.
<script language="javascript">
function usernameavailability() {
var str = "uname=" + document.register.username.value ;
var URL = "username_chk.php";
req = false;
// section for native XMLHttpRequest object
if(window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
// section for IE/Windows ActiveX version
} else if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
if(req) {
req.open( "POST", URL,true);
req.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded; charset=UTF-8");
req.setRequestHeader("Content-length", str.length);
req.setRequestHeader("Connection", "close");
req.send(str);
}
}
</script>
|
|
The passed arguments can be accessed from the '$_POST' or '$_REQUEST' array in PHP.
|
|
|
|