Trouble with jQuery Ajax load() method
Sunday, October 21st, 2007 by Favio
When you do a search on google with the title of this post as the keywords expecting to get some light on a problem you have been banging your head for some hours; it is most likely you won't find a solution. The first reason is that jQuery does rock, and the second is that the documentation for the load() method is very clear. So I'm writing this to make a stop in time and try not to forget this small observation.
As part of a side project of mine, I'm coding a small app with CI as the php framework and jQuery as the js one. Problem is: I've been trying to Ajax load some content without success for some time.
The Problem
I can't load the following content:
-
<form action="<?php echo base_url(); ?>ranges/edit" id="addRangeForm" method="post">
-
<fieldset>
-
<label for="name">Name:</label>
-
<input type="text" name="name" id="name" value="<?php echo $this->validation->name;?>" />
-
<label for="display">Display Name:</label>
-
<textarea name="display_name" id="display" rows="1" cols="20"><?php echo $this->validation->display_name;?></textarea>
-
<label for="description">Description:</label>
-
<input type="hidden" name="id" value="" />
-
<textarea name="description" id="description" rows="5" cols="20"></textarea>
-
</p>
-
<p class="clear"></p>
-
</fieldset>
-
</form>
Firebug says the request is being done, it shows the response on the console, but not on the browser window. After switching to $.get, loading in other containers (only when loading into the whole document object, the form was displayed), and trying static content. I finally managed to find why it wasn't showing.
The Solution
Remove the opening form tag! This one:
-
<form action="<?php echo base_url(); ?>ranges/edit" id="addRangeForm" method="post">
And we got us some nice content load.
After investigating the issue further, the reason of this behavior was that the id of the form that I wanted to load, was already being used! So the solution really is:
Id's must be unique through the whole document.
Conclusion
Fun times. (>_<)
This entry was posted on Sunday, October 21st, 2007 at 10:17 pm and is filed under Ajax, Javascript. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Leave a Reply
Old and not that old articles
« C’mere
jQuery.slideDown flicker when a form is inside the sliding container »
