jquery is not redirecting to controller? |
[eluser]solid9[/eluser]
Hi guys I have these jQuery codes below, Code: $(document).ready(function(){ and in my <b>controller</b>, I have this method Code: function submit() Just wondering why is it every time I press the submit button in the view the page don't redirect to <b>main</b> controller. What might be the reason for this?
[eluser]CroNiX[/eluser]
Is your "#submit" element an actual submit input type form element? If so, you need to prevent the default behavior of the submit button. Code: $(document).ready(function(){
[eluser]solid9[/eluser]
@CroNiX I already modified the codes, see below, Code: $(document).ready(function(){ Is my changes correct CroNix? By the way thanks for your reply.
[eluser]InsiteFX[/eluser]
Try this: Code: url: <?php echo base_url();?>+"main/submit", Also in your submit method you should check for an ajax call: Code: if ($this->input->is_ajax_request())
[eluser]solid9[/eluser]
@insideFX I already did your suggestion. But the page keep refreshing every time I press the submit button. and nothing happened, below is the view view [code] <div id="addCommentContainer"> <form name="addCommentForm" id ="addCommentForm" method="post"> <div> <input type="hidden" name="swapid" value="<?php echo $swapid ?>"> <label for="name">Name </label> <input type="text" name="name" id="name" /><br> <label for="email">Email </label> <input type="text" name="email" id="email" /><br> <label for="body">Comment </label> <textarea name="comment" id="comment" cols="20" rows="5"></textarea><br> <input type="submit" name="offer_submit" id="offer_submit" value="Submit" /> </div> </form> <br><br> </div> [code] By the way I change the name and id of the button. I also change the jQuery codes to match the name/id of the button.
[eluser]InsiteFX[/eluser]
I may be wrong here, but I think you need the action statement in your form. Also you have a space between the id and = Code: <form name="addCommentForm" id="addCommentForm" action="where you want it to go!" method="post"> Here is an article on it but it's for ExpressionEngine. jQuery and ExpressionEngine Form Processing
[eluser]CroNiX[/eluser]
Probably because your submit button has an id of "offer_submit". Check your jquery, you are targeting #submit, which doesn't exist.
[eluser]ojcarga[/eluser]
Some things to test with: - Check the JQuery library inclusion Code: <script... - Make sure the selector is which it should be Code: $("#submit") Code: .submit( Code: .click( Code: "&name;="+name+"&email; - Change the url: to the way @InsiteFX said. If not, post the actual code, controller and view, both.
[eluser]InsiteFX[/eluser]
Here is another way to get the base_url into jQuery: Code: // Replace the $ in script tags with s Now you can use either base_url+"" or site_url+"" |
Welcome Guest, Not a member yet? Register Sign In |