{ "Venue" : [ 
 { "venue_id":"1", "name":"Starbucks"},
       { "venue_id":"2", "name":"Tim Hortons"}
  ],  
"Event" : [ { "event_id":"1", "name":"EVent1"}, { "event_id":"2", "name":"EVent1"}
] }

I have a php page, "data.php" which will echo the data in the above json format.

But if I set up php header of "data.php" as this

header('Content-type: application/json');

Browser firefox cannot open "data.php", it will pop up a window said "this is a php file. do you want to open it with dreamwever or do you want to save it on disk?"

But if I set up the header like

header('Content-Type: text/plain, charset=utf-8');

The data.php is working fine.

The right header for Json is

header('Content-type: application/json');

So which header I am supposed to use?

Or header('Content-type: application/json'); is for the json file. But the data output in json format should still use header('Content-Type: text/plain, charset=utf-8'); ?

    When you send a content-type header, you are telling the browser what application it should use to handle the output that follows. Sounds to me like the browser is thinking that this is some novel mime type or something that needs to be handled with a helper application. I'd be willing to bet that a content-type of text/html or text/xhtml would probably work? or maybe text/javascript?

      Write a Reply...