// you’re reading...

Development JavaScript PHP 

Does jQuery support JSON from the X-JSON Header?

Yes, you need to call the getResponseHeader method of the XMLHttpRequest object, and do the JSON de-serialization manually:

function getHeaderJSON(xhr) {
  var json;
  try { json = xhr.getResponseHeader('X-Json') }
  catch(e) {}

  if (json) {
    var data = eval('(' + json + ')'); // or JSON.parse or whatever you like
    return data
  }
}

Discussion

No comments yet.

Post a comment

About

This in the personal Blog from Fabian Siebler, a Lead Developer and Projektmanager from Germany.

more...

Twitter