Skip to content

Instantly share code, notes, and snippets.

@sumn2u
Created July 5, 2015 13:40
Show Gist options
  • Save sumn2u/bc4da086002538a61725 to your computer and use it in GitHub Desktop.
Save sumn2u/bc4da086002538a61725 to your computer and use it in GitHub Desktop.
ajax example with XMLHttpRequest
var xRequest1;
if (window.XMLHttpRequest)
{
xRequest1 = new XMLHttpRequest();
} else {
xRequest1 = new ActiveXObject("Microsoft.XMLHTTP");
}
//Send the proper header information along with the request
xRequest1.onreadystatechange = function() {
if ((xRequest1.readyState == 4) && (xRequest1.status == 200))
{
var respone = xRequest1.responseText;
// alert(respone);
if( respone.match(/success/g)){
window.location="index.jsp";
}else{
alert(" nott match");
}
}
};
var data = "uname=" + encodeURIComponent($("[name='uname']").val())
+ "&upass=" + encodeURIComponent($("[name='upass']").val());
xRequest1.open("post", "loginCheck.jsp", "true");
xRequest1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xRequest1.send(data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment