![]() |
Prototype Ajax w/ CI Help - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Prototype Ajax w/ CI Help (/showthread.php?tid=28483) |
Prototype Ajax w/ CI Help - El Forum - 03-12-2010 [eluser]jaystang[/eluser] Hey guys, I'm a bit new to CI and I've been playing around with trying to make an Ajax call to my controller passing a JSON object. Below is the code I've got so far... Javascript Code: Code: var categoryParams = {'categoryId': 123456, 'applicationId': 789123}; PHP Code: Code: public function testajax() My issue is with passing an object. Everything works fine if I only pass one integer rather then the object. Any thoughts what I'm doing wrong here? Thanks. Prototype Ajax w/ CI Help - El Forum - 03-12-2010 [eluser]bretticus[/eluser] Why do you need to call .toJSON() on categoryParams. It's already a JSON object, no? Prototype Ajax w/ CI Help - El Forum - 03-12-2010 [eluser]jaystang[/eluser] I technically don't need it. I had another object I was originally passing through the toJSON() method. I just tried not using that and it's still not working for me. Prototype Ajax w/ CI Help - El Forum - 03-12-2010 [eluser]bretticus[/eluser] So I have a few suggestions. Turn on profiling so you can see what is actually being posted from PHP's perspective. Also, get and install firebug so you can see what is being sent to the ajax url. Finally, is there any reason why you are setting content type to text/json? It's been awhile since I used Prototype, but it seems like if you send an object as params, that Request turns them into real post variables. Prototype Ajax w/ CI Help - El Forum - 03-12-2010 [eluser]jaystang[/eluser] I actually wasn't sure if i needed the "text/json" stuff or not so I tried it both ways. Anyway I'm watching everything go across the wire in firebug and I can see it seems to be working (see attached screenshot), but when i profile it on the server side i'm seeing "No POST data exists" so I'm not sure where it's getting lost. Prototype Ajax w/ CI Help - El Forum - 03-12-2010 [eluser]jaystang[/eluser] Ok cancel that, I got it working. Final working code example... Javascript Code: Code: new Ajax.Request(baseUrl + 'index.php/applications/Applications/testajax/', PHP Code: Code: public function testajax() Prototype Ajax w/ CI Help - El Forum - 03-12-2010 [eluser]bretticus[/eluser] Sweet, glad you got it working. Another good tool to have in your bag for AJAX is firephp. It plugs right into firebug. You basically tell it to log from your PHP code (I use it as a codeigniter lib.) Cheers! Prototype Ajax w/ CI Help - El Forum - 03-12-2010 [eluser]jaystang[/eluser] Ah great, I will definitely check that out, thanks. |