AJAX troubleshoot if anyone is bored. :-) |
[eluser]stevefink[/eluser]
This isn't a CI issue. It's a user error. :-) Anyhow. I have a URL that looks like this: http://f1auto/console/addvehicle/photos/1 This URL is mangled with URI routing, so if clarification is needed after this post, I'll be sure to respond. I have a DIV within the main view that looks like this: Code: <div id="showPhotos"> get_photos resembles the following: Code: function get_photos() and finally get_photos in the model resembles the following: Code: function get_photos($vehicle_id) I'm trying to load a separate view depending on the 4th URI segment which is the $vehicle_id. For the sake of brevity and debug, the .load() is calling: Code: <?php foreach($photos->result() as $photo): ?> However after debugging with Firebug, I seem to be getting zero data back from the server. Can anyone be kind enough to help me recover my fumble? Thanks!
[eluser]coolfactor[/eluser]
I don't see where you're loading that view. Your get_photos() method is returning the $photos array directly.
[eluser]stevefink[/eluser]
Eeep, just noticed get_photos() was out of date in my controller. The view gets loaded here: Code: function get_photos()
[eluser]stevefink[/eluser]
What if I just eliminate AJAX from the equation to make this a tad simpler. I revised my function to look like this in the controller: Code: function index() And my photos_view contains the following: Code: <div id="showPhotos"> Still nothing showing up. log_message DEBUGGING shows the following dump of $data: Code: DEBUG - 2007-08-27 19:36:31 --> Array
[eluser]FrankieShakes[/eluser]
Stupid question... but what does your DB table look like? Can you show a sample row of the data you have in it?
[eluser]Luipaard[/eluser]
I could be wrong, but I believe you can't put javascript in your HTML just like that. It has to included from a JS file, or embedded within script tags? EDIT: Nevermind, the forum is filtering the script tag.
[eluser]obiron2[/eluser]
Sorry, I can't see where you are calling a javascript function which would then run the Ajax callback. The ajax needs to pass the full URI to CI and then have a destination JS function to process the result (normally replace innerHTML of a DOM object with the responseText) The beauty of using CI with Ajax is you can test the URI call independently of the Ajax just by keying the URI in the the resource bar. Are you wrapping the Ajax call in an object? If you are creating and only using one ajax object and you can have several ajax calls going at once, the original call can get overwritten. use this http://www.hunlock.com/blogs/The_Ultimate_Ajax_Object to create the ajax object and each call can then have a separate object. This has saved me no end of grief. I have read somewhere that some browsers will restrict you to two syncronous XMLHttp requests. obiron PS use Firefox with Firebug. You can see exactly what is going on with the XMLHttp requests
[eluser]jkevinburton[/eluser]
Just to clarify that statement. You can call a PHP file in javascript (ajax method) and have it return javascript.. as long as you make the header text/javascript. [quote author="Luipaard" date="1188295158"]I could be wrong, but I believe you can't put javascript in your HTML just like that. It has to included from a JS file, or embedded within script tags? [/quote] |
Welcome Guest, Not a member yet? Register Sign In |