I am developing plugin in wordpress, i used select tag element, i need the value to be stored in the database on change the option values , but it seems ajax is not working .below is my code ,
this is script code
function ajaxFunction(str,id) {
var payment_selected = str;
var id=id;
var queryString = "&id_took=" + id + "&sel=" + payment_selected;
jQuery.ajax({
var data = { 'action' : 'my_action',
'queryString':queryString
};
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});
}
<select name='payment_select' id="payment_select" onchange="ajaxFunction(this.value,<?php echo $row->id ?>)">
<option value="Payment Due">Payment Due</option>
<option value="Payment completed">Payment Completed</option>
</select>
/*below one i have written in my plugin code */
<?php
add_action( 'wp_ajax_my_action', 'my_action' );
function my_action() {
global $wpdb;
$id_selected = $_POST['id_took'];
$id = $_POST['id'];
$table_name_payment = $wpdb->prefix . "online_booking_system_model";
if($whatever2=="Payment completed")
{
$result_pay = $wpdb->query("UPDATE $table_name_payment SET
payment_status = $id_selected
WHERE id = $id ");
echo "success";
}
}
?>
</div>