View Full Version : Resource interpreted as script but transferred with MIME type application/json.

Dav Yaginuma
12 Sep 2010, 6:40 AM
I'm getting this warning in my JS console when making an Ext.util.JSONP.request() against my local rails server.

The code is pretty much identical to the example geo twitter code from the Sencha Touch website, in fact somewhat simplified now since I took out the code that actually process the json results:

var refresh = function() {
url: 'http://localhost:3000/events.json',
callbackKey: 'callback',
callback: function(data) {
/*data = data.results;

The geo twitter example code works fine, so I compared the HTTP headers from twitter and my local rails app. Nothing seemed amiss there, they both set the content-type to application/json as expected. I've looked at the response in the debugger and it looks like valid JSON to me (I even threw it into JSONlint to be sure). Since the JSON is being interpreted as JS, the script blows up with "Uncaught SyntaxError: Unexpected token :". I never get that 'DATA' console output so I don't think the callback function is ever getting called.

Anyone have an idea on what I need to do to fix this? I hate running into a stumping error like this so quickly!

12 Sep 2010, 4:45 PM
Is there any reason you're using a JSONP request for local data?

Dav Yaginuma
12 Sep 2010, 6:00 PM
I was just copying the main example from the website. But thanks, after looking deeper into JSONP I see now that it requires the server to do some special processing. Ironic since being able to read JSON from non-origin servers is important for my app (the native iPhone version loads JSON from anywhere on the web), but since it can't handle raw JSON responses I can't use it.

I've got it working now with a regular Ajax call and the Ext.util.JSON.reader.