Created
December 10, 2012 15:52
-
-
Save MikeRogers0/4251395 to your computer and use it in GitHub Desktop.
Returns value from test.php file
This file contains hidden or 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
function doSomething(xhr) { | |
var test = xhr.responseText + 'was found'; | |
alert(test); | |
} | |
function ajaxReturn (file,func,data) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open("POST",file, false); // Adding in the false, means send will wait for a reply until continuing with the code. | |
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); | |
xhr.send(data); | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
func(xhr); | |
} | |
} | |
ajaxReturn('test.php',doSomething); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment