使用ajax更新表单

I have list of table which displays users information. There will be an amend link at the top. I need to update the form through Ajax rather than moving on to another page to update it. This is my code.

  <?php  while ($row = mysql_fetch_assoc($displayer)){

            echo("<tr><td>First Name</td><td>" . $row['first_name'] . "</td> </tr>");
            echo("<tr><td>Last Name</td><td>" . $row['last_name'] . "</td> </tr>");
            echo("<tr><td>Email</td><td>" . $row['email'] . "</td> </tr>");
            echo("<tr><td>Country</td><td>" . $row['country'] . "</td> </tr>");

            echo "<a  class='page' href='amend.php?id=" .urlencode($row['users_id']) . "&amp;firstname=" .urlencode($row['first_name']) . "&amp;lastname=".urlencode($row['last_name']) ."'>Amend Record</a></td></tr>";
            ?>

Could any one tell me how to update the form using Ajax on the same page itself.

much details go into these that would require a very lengthy answer...nonetheless I am going to stress some important starting points.

First you need a JS file with a handler about the link. When the link is clicked a ajax request must be made...there are various way to do that but I personally use jquery's $.ajax....inside the request you must gather the variables that reflect the values of the form inputs....then you send these values to a PHP script that makes validation and if this is successful update the corresponding values in the database.Inside the request you must also specify the URL that the this script resides.

This ajax request though is comprised of 2 important callbacks...error and success...in them you must write code that will deal with the situation if the request succeeds or not....for example you update he values in form when you are certain that this has indeed happen in the database and you can a make check for that in the PHP script...whatever values the PHP script echoes back must be done with json_encode...and you can access these values with the data argument of the success callback.AS I said there is an error callback also..this is triggered by various causes...it the URL is wrong or JSON is not returned from the server.

These above are just starting points...I am laying out a general approach.

/* AJAX using jQuery */

// attach event to your <a> upon click
$(document).on('click','a.page', function(e) {
    e.preventDefault()
    var sURL = $(this).attr("href"); // url to call for amend
    update( sURL ) // call the function update
});

// update() function that is called after clicking anchor tag 
function update( _url ) 
{        
    $.ajax({
        method: 'POST',
        url: _url,
        success: function() { 
            alert("Amend Success)";
        },
        error: function( c ) {
            alert("Internal server error. Check your browser console");
            console.log( c.responseText )
        }
    })
}

NOTE: Put this before </body> tag