First of all, in your jquery event handler the action
parameter’s value should be the string after wp_ajax_
and wp_ajax_nopriv_
. So in your example the action
should be update_records
. So display_func
is wrong.
Then in line 3 of your php code here the echo
keyword should be removed.
So your php code should be like this:
function update_records(){
global $wpdb;
$id = $_POST['update_record'];
$db_updated = $wpdb->update( $wpdb->prefix.'contact_form',
array(
'names' => $_POST['update_name'],
'emails' => $_POST['update_email'],
'gender' => $_POST['update_gender'],
'age' => $_POST['update_age']
),
array( 'ID' => $id )
);
}
add_action( "wp_ajax_update_records", "update_records" );
add_action( "wp_ajax_nopriv_update_records", "update_records" );