1

Is it possible to remain the values in textbox after submited the form and remain the same page using jQuery ajax?

I'm sorry that I don't have examples to demonstrate.

Thanks in advance.

Raymond
  • 572
  • 4
  • 13
  • 28

2 Answers2

1

In your submit callback you could preventDefault the submit event. You would then just handling it by yourself with ajax.

$('#yourform').submit(function(event) {
    event.preventDefault(); // disable default submit behaviour of the browser
    $.post($(this).attr('action'), $(this).serialize()); // handle the post via ajax
});
<form id="yourform" action="script.php">
    <input type="text" name="field">
    <input type="submit" value"Go">
</form>
ohcibi
  • 2,518
  • 3
  • 24
  • 47
0

You can submit your page using jquery/ajax look at it- suppose html code is-

<form id="target" action="destination.html">
<input type="text" value="Hello there" />
<input type="submit" value="Go" />
</form>

now ajax code will be-

$('#target').submit(function() {
alert('Handler for .submit() called.');
return false;
});
Prateek Shukla
  • 593
  • 2
  • 7
  • 27