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.
JSONP is still useful for older browser support, but given the security implications, unless you have no choice CORS is the better choice.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With