January 6, 2012

json parse example

function httpRequest(url,params)
{

var http = false;
if(navigator.appName == “Microsoft Internet Explorer”) {
http = new ActiveXObject(“Microsoft.XMLHTTP”);
} else {
http = new XMLHttpRequest();
}

http.open(“POST”, url, true);

//Send the proper header information along with the request
http.setRequestHeader(“Content-type”, “application/x-www-form-urlencoded”);
http.setRequestHeader(“Content-length”, params.length);
http.setRequestHeader(“Connection”, “Keep-Alive”);

http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {

var json_array = JSON.parse(http.responseText);
}
}
http.send(params);

}

Last updated: March 19, 2014