Created
May 7, 2014 18:23
-
-
Save Med116/c5119c89f3213683fb59 to your computer and use it in GitHub Desktop.
ajax javascript get
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
function getAjax(){ | |
var xmlhttp; | |
if (window.XMLHttpRequest) | |
{// code for IE7+, Firefox, Chrome, Opera, Safari | |
xmlhttp=new XMLHttpRequest(); | |
} | |
else | |
{// code for IE6, IE5 | |
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); | |
} | |
return xmlhttp; | |
} | |
function getUrlResponse(url, params, callback){ | |
var http = getAjax(); | |
if(params){ | |
url += "?"; | |
} | |
for(param in params){ | |
url += param + "=" + encodeURIComponent(params[param]) + "&"; | |
} | |
http.open("GET", url,true); | |
http.send(url); | |
http.onreadystatechange = function(){ | |
if (http.readyState == 4){ | |
callback(http.responseText); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment