JQuery UI Question:

How can we submit a form by ajax using Jquery?

Tweet Share WhatsApp

Answer:

Please follow below code to submit a form by ajax using jquery

$(‘#formid).submit(function() {
$.ajax({
type: “POST”,
url: “back.php”,
data: “name=php&location=india”,
success: function(msg) {
alert( “Data Saved: ” + msg );
}
});
}

Where formid is the form ID.”POST” is the method by which you want to send data.You can also use “GET” method.”back.php” is the php file which you want to call.”name=php&location=india” This is values of control. success: function(msg){ alert (“Data Saved: ” + msg); } This is a success function, This will execute after success of you post.Often in Ajax back.php does not refresh because this is cached by browser. To avoid this issue add [cache: false,] in above code.Loads data synchronously. Blocks the browser while the requests is active. It is better to block user interaction by other means when synchronization is necessary.

To avoid this issue add [async: false,] in above code.

Download JQuery User Interface PDF Read All 17 JQuery User Interface Questions
Previous QuestionNext Question
How can we get value of textbox in jquery?How can we apply css in div element using JQuery library?