1

I keep getting this error

1Resource interpreted as Script but transferred with MIME type application/json.

I am trying to use jquery query to grab my json form a php file on a separate domain here is my php code.

json.php

<?php
header('Content-type: application/json');
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
?>

and here is my jquery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> 
<script type="text/javascript">

$(document).ready(function() {

    var surl =  "http://dropp.users35.interdns.co.uk/json.php";

         $.getJSON(surl,  function(rtndata) {
             console.log(rtndata);
    });

 });


</script>

ok if i change my url to

http://dropp.users35.interdns.co.uk/json.php?callback=?

i then get this error?????

1Resource interpreted as Script but transferred with MIME type application/json.
tshepang
  • 10,772
  • 21
  • 84
  • 127
DCHP
  • 1,101
  • 6
  • 28
  • 53

2 Answers2

1

I believe the answer to your question involves using JSONP because it involves cross domain scripting...

It is discussed in a couple of similar questions on StackOverflow: Resource interpreted as script but transferred with MIME type application/json. & parsererror

and here: https://stackoverflow.com/questions/267546/correct-http-header-for-json-file

Community
  • 1
  • 1
AdrianB
  • 110
  • 1
  • 8
0

There is no callback in the returned javascript whether I specify callback= or not:

$ curl -v http://dropp.users35.interdns.co.uk/json.php?callback=test_callback
* About to connect() to dropp.users35.interdns.co.uk port 80 (#0)
*   Trying 83.170.124.37... connected
* Connected to dropp.users35.interdns.co.uk (83.170.124.37) port 80 (#0)
> GET /json.php?callback=test_callback HTTP/1.1
> User-Agent: curl/7.21.3 (x86_64-pc-linux-gnu) libcurl/7.21.3
> Host: dropp.users35.interdns.co.uk
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Tue, 16 Aug 2011 03:04:35 GMT
< Server: Apache
< X-Powered-By: PHP/5.3.2-1ubuntu4.9
< Transfer-Encoding: chunked
< Content-Type: application/json
< 
* Connection #0 to host dropp.users35.interdns.co.uk left intact
* Closing connection #0
{"a":1,"b":2,"c":3,"d":4,"e":5}

You must wrap your JSON with a callback if you want it to work:

    test_callback({"a":1,"b":2,"c":3,"d":4,"e":5});
sanmai
  • 23,569
  • 11
  • 54
  • 73