Posts Tagged ‘web’

It’s a bit of a head-scratcher at first, seeing as the jQuery docs mysteriously disavow a postJSON possibility, let alone a function, but it’s definitely doable. So here’s the glorious code: function postjson(url,data,bS,s,e){ $.ajax({type:”POST”,url:url,data:data,dataType:”json”, beforeSend:bS,success:s,error:e});} Use it like so: postjson(“name.php”,”name=Bob”, function(){$(“#name”).text(“…”);}, function(json){$(“#name”).text(json.name);}, function(){$(“#name”).text(“Error”);}); If name.php’s output looks like this… {“name”:”Bob”} …the above should, upon execution, […]