views:

619

answers:

2

Hello. I have a problem with using the jQuery JSONP function $.getJSON in CodeIgniter. The url from which the json is grabbed from is: http://spinly.000space.com/index.php/admin/isloggedin

Now, the problem, is that I have a demo.html file that runs the $.getJSON function and grabs the data from the url I denoted above.

DEMO.html looks like:

<html>
<head>
  <script src="http://www.spinly.000space.com/public/js/jquery.js"&gt;&lt;/script&gt;

  <script>
  $(document).ready(function(){
  var myurl = "http://spinly.000space.com/index.php/admin/isloggedin/&amp;jsoncallback=?";

    //myurl = "http://com.lnk.bz/jsonp.php?sleep=3&amp;jsoncallback=?";
    $.getJSON(myurl,function(adat) {
        alert(adat);
     //   clearTimeout(t);
    }); 

  });
  </script>
</head>
<body>
  <div id="images">
  </div>
</body>
</html>

So when I run the demo.html file nothing happens, although as you can see it's supposed to alert the data returned, when I change the url to a another one that doesn't use CodeIgniter as the framework I get alert function running, although in this case while using the url that's backed up with CodeIgniter it doesn't work.

Does anyone have a solution to my problem? I'd really appreciate if you gave me some feedback.

Thanks!

A: 

The ampersand in your url is wrong:

loggedin/&jsoncallback=?

It should be something along the lines of

loggedin/?jsoncallback=?

Running that i get the response of

jsonp123( ...

Which means it attempts to call the jsonp123 function, and the adat part of your code is never used at this point.

postpostmodern
postpostmodern: I've changed the code, and now http://spinly.000space.com/index.php/admin/isloggedin/ displays {"title":"user online","user":{"online":"yes"}} and still it doesn't work.
Emil Hajric
The getJson method makes a new function which is replaced into your url, and as sent is something like: loggedin/?jsoncallback=jsonp1239837994134echo $cb;echo '({"test":true})';It is a little confusing.
postpostmodern
A: 

By default CI doesn't allow query strings, so did you enable enable_query_strings in your config.php?

$config['enable_query_strings'] = TRUE;
Jason