Skip to content

Instantly share code, notes, and snippets.

@Med116
Created May 7, 2014 18:23
Show Gist options
  • Save Med116/c5119c89f3213683fb59 to your computer and use it in GitHub Desktop.
Save Med116/c5119c89f3213683fb59 to your computer and use it in GitHub Desktop.
ajax javascript get
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