Created
July 5, 2015 13:40
-
-
Save sumn2u/bc4da086002538a61725 to your computer and use it in GitHub Desktop.
ajax example with XMLHttpRequest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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