JSON

From Code Trash
Jump to: navigation, search

JSON Response from php script

Javascript Response Snippet

	var jso = jsonRequest(base_url+'ajax.php',"command=sekoda&scode="+getjsText('scode'),false)
	document.getElementById('scodespn').innerHTML = jso.scode
	if(jso.err)jsalert("Invalid total value.")

Javascript JSON response processing

function jsonRequest(args,param,mode)
{
	var jax = jPreset(args,param,mode)
	jax.send(param)
	try{ return eval('('+jax.responseText+')') }
	catch(e) {
		if(arguments.length>3)jsalert(trim(strip_tags(jax.responseText)))
		else jsalert("Unable to process the response code");
	}
}
 
 
function jPreset(args,param,mode)
{
	var jax = createAjax();if(!jax)return;
	jax.open("POST",args,mode)
	jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	if(mode)jax.onreadystatechange = function() { if(jax.readyState==4)jResponseBool(jax); }		
	return jax;
}