sagar sagar - 5 months ago 19
jQuery Question

jquery ajax call to execute php script

I have created an HTML form name form.php to take the firstname and lastname from the user.

<form action="form.php" method="post">
Firstname: <input type="text" name="firstname"><br>
Lastname: <input type="text" name="lastname"><br>
<input type="submit">

I wanted to use jquery ajax method to insert value in the database. how to write php-script and jquery call. Iám completely new to jquery and ajax can anyone please help me?


Try some thing like this:

    url: 'process.php',
    type: 'POST',
    data: {
        var1: val1, // variables
        var2: val2
    success: function(response) { // response from process
        // do your stuff here


$var1 = $_REQUEST['var1'];
$var2 = $_REQUEST['var2'];
// do your stuff here