« Limonade Framework | Main | SQL for clearing out Events webservice transactions »

July 03, 2009

jQuery JSON and AJAX for off-domain content

Your jQuery code looks like this:

$.ajax({
	dataType: "jsonp",  
	json: "callback",  
	url: "http://<?=$paths['host']?>/event_registration/how_many_registered.ws.php?event_id=<?=$event['event_id']?>",
	success: function(json){
		if(json["max"] > 0){
			if(json["status"] == "open"){
				document.getElementById("registration_container").innerHTML = document.getElementById("registration_container").innerHTML + " - " + json["spaces"] + " places left.";
				}
			else{ 
				document.getElementById("registration_container").innerHTML = "%lt;a name=\"sorry\" style=\"color: #ee174c\">Sorry. Registration closed. This event is full</a>"; 
				}
			}
		}
	});

The PHP looks like this (where $r == $_REQUEST):

print $r['callback'].'( '.json_encode($reply).' )';

Tags: JSON

Posted by pj at July 3, 2009 10:37 AM

Comments