0

jQuery submit function is not working in following case and when I remove return false from this code then it starts working.

JavaScript

function insertQuotit() {
    jQuery.ajax({
        url: "<?php echo bloginfo('template_url')?>/quotitinsert.php",
        type: "post",
        data: jQuery('#quotitInsert').serialize(),
        success: function (res) {

            jQuery("#quotitInsert").submit();

        }
    });
    return false;
};

HTML

<form name="form1" method="post" id="quotitInsert" action="http://www.abc.net" >
<input type="submit" name="Submit" value="Submit" id="submit"  onclick="return insertQuotit();"/>
Martin Devillers
  • 17,293
  • 5
  • 46
  • 88
user3454835
  • 113
  • 1
  • 14
  • The return value of an event handler determines whether or not the default browser behavior should take place as well. by using `return false;` you are preventing default behavior. You should read http://stackoverflow.com/questions/10729198/what-does-return-false-do – Satpal Mar 28 '14 at 09:34

4 Answers4

0

You're clicking on a submit button, whose default behavior is to submit a form and reload the page.

By using return: false, you prevents the browser from performing that default action.

Felix
  • 37,892
  • 8
  • 43
  • 55
  • what is the solution? i can't remove return false because on form submit i have to perform 2 actions. when first action completes only then i will submit form as you can see ajax request when i submit form – user3454835 Mar 28 '14 at 09:39
0

Try this

window.location = "http://www.abc.net" ;

instead of

jQuery("#quotitInsert").submit();
Sudharsan S
  • 15,336
  • 3
  • 31
  • 49
0

Change

<input type="submit" />

To

<input type="button" />

and remove return false

Kiranramchandran
  • 2,094
  • 16
  • 30
0

Try inserting this in your form field. onsubmit="return false;"

<form onsubmit="return false;" method="post" id="quotitInsert" action="http://www.abc.net" >

this should prevent form from getting submitted.

Leroy Mikenzi
  • 792
  • 6
  • 22
  • 46