A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearJSONP in CodeIgniter - page 1
User InfoPosts
JSONP in CodeIgniter#1
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!

posted date: 2009-04-15 14:28:00


Re: JSONP in CodeIgniter#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-15 14:28:01


Re: JSONP in CodeIgniter#3
The ampersand in your url is wrong: loggedin/&jsoncallback=?It should be something along the lines ofloggedin/?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.

posted date: 2009-04-15 14:56:00


Re: JSONP in CodeIgniter#4
postpostmodern: I've changed the code, and now spinly.000space.com/index.php/admin/isloggedin displays {"title":"user online","user":{"online":"yes"}} and still it doesn't work.

posted date: 2009-04-15 15:18:00


Re: JSONP in CodeIgniter#5
The getJson method makes a new function which is replaced into your url, and as sent is something like: loggedin/?jsoncallback=jsonp1239837994134&_=1239838173986 Try replacing your php with this: $cb = $_GET['jsoncallback']; echo $cb; echo '({"test":true})'; It is a little confusing.

posted date: 2009-04-15 15:36:00


Re: JSONP in CodeIgniter#6
By default CI doesn(t allow query strings, so did you enable enable_query_strings in your config.php?$config[(enable_query_strings(] = TRUE;

posted date: 2009-05-01 06:43:00


Re: JSONP in CodeIgniter#7
looking for a good way to implement jsonp in CI ...

posted date: 2011-07-27 02:22:00


Re: JSONP in CodeIgniter#8
Before elaborate more, can you specify what version CI you use, and is it "Core" or "Reactor" ?

posted date: 2011-07-27 04:22:00


Re: JSONP in CodeIgniter#9
Reactor version..

posted date: 2011-07-27 18:47:00


Re: JSONP in CodeIgniter#10
Also make sure that you have $config[(allow_get_array(] set to TRUE in config.php. This will allow you to use $this->input->get();in your controllers.

posted date: 2011-07-27 20:11:00


Re: JSONP in CodeIgniter#11
i think the issue that you are facing is because of the restriction by browsers on not allowing cross domain requests. I am guessing that you are hosting your app on some other domain/sub-domain and that is what is causing this issue.What you need to use is JSONP i.e Json with padding. Details here: http://en.wikipedia.org/wiki/JSONPLook at jsonp in jquerys ajax api here: http://api.jquery.com/jQuery.ajax/ and see if that solves your problem.

posted date: 2011-07-30 11:01:00


Re: JSONP in CodeIgniter#12
This URL doesn't work anymore.

posted date: 2011-08-02 10:54:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.