How to submit a from without reloading page?

Hello Friends,

There is a question.

How to submit a form without reloading page with the help of ajax,php or jquery ?

Ajax and jQuery are used on the client-side. You can choose one of these two.

Well, AJAX really means Asynchronous JavaScript and XML. This is the method that you would use to call a URL (PHP, HTML, or whatever) without reloading the page.

Now, you can make an AJAX call with plain JavaScript. JQuery is just a library over JavaScript that will help you make the calls easier.

Here’s an example of an AJAX call with JQuery:


<? // index.php ?>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<title>ajax call</title>
</head>
<body>
Hello!
</body>
<script>
$( document ).ready(function() {
$.ajax({
  url: 'somePhpPage.php',
  type: 'GET',
  data: 'someParam=myParam',
  success: function(data) {
	//called when successful
        alert('Success:' + data);
  },
  error: function(e) {
	//called when there is an error
        alert('Ooops, an error occured!');
  }
});
});
</script>
</html>

And the PHP file that is called by the AJAX:

<?
// somePhpPage.php
echo 'The value of your param was:' . $_GET['someParam'];
?>

This should (I didn’t tested it to be honest) write the following message: The value of your param was: myParam
in a JavaScript alert box.

What happened is:
index.php loaded up. Your browser executed the JavaScript code. This JavaScript code is, in fact, in the form of JQuery syntax. This code called, with Ajax, the page “somePhpPage.php” with the parameter “someParam” with its value at “myParam”.

The “somePhpPage.php” just outputs the value of the parameter passed + another message.

Then, the Jquery code takes the output of the SomePhpPage.php and writes it in an alert box.

Can we use javascript in the place of jquery to submit a form without reloading page .

I thing that javascript is more easy then jquery so i like to use javascript.

If JQuery can do it, you can do it with plain JavaScript, It’ll just take more lines of code most of the time.
Check out: