Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONP in CodeIgniter

Tags:

People also ask

What is JSONP used for?

JSONP is a method for sending JSON data without worrying about cross-domain issues. JSONP does not use the XMLHttpRequest object. JSONP uses the <script> tag instead.

Does JSONP still work?

JSONP is still useful for older browser support, but given the security implications, unless you have no choice CORS is the better choice.

How does JSONP request work?

Standard JSON Asynchronous requestThe browser makes an asynchronous POST request to the server slapping its parameters to the service in the body. The server responds with a string of JSON data. A success handler of the request fires and the string is converted into a Javascript Object to be used in the application.

What is JSONP API?

JSON Processing (JSON-P) is a Java API to process (for e.g. parse, generate, transform and query) JSON messages. It produces and consumes JSON text in a streaming fashion (similar to StAX API for XML) and allows to build a Java object model for JSON text using API classes (similar to DOM API for XML).


I have a problem with using the jQuery JSONP method $.getJSON in CodeIgniter. The URL from which the JSON is grabbed from is the following:

http://spinly.000space.com/index.php/admin/isloggedin  

The Problem is that I have a demo.html file that runs the $.getJSON method, and grabs the data from the URL I denoted above.

demo.html:

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

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

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

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

When I run demo.html nothing happens. 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, but 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 in advance!