This is how I’ve been handling my ajax until now:
@header("Content-Type: text/html; charset=".get_option('blog_charset'));
and the js:
$.ajax(....
...
success: function(response){
var obj = eval('('+response+')');
if(obj.somedata == ....)
...
And now I want to use application/json as content type so the javascript changes to:
$.ajax(....
...
success: function(response){
if(response.somedata == ....)
...
Looks better 🙂
But I’m curious to know if this will work in all browsers? So far it tested OK in FF, Opera and IE 8.
yes. JSON is not so much browser-dependent/specific as it is Javascript-specific, so assuming you have a browser (any browser) that has a full implementation of javascript, then it will support JSON. see here