Created
July 27, 2018 04:18
-
-
Save raiden808/6994c81c6f358e0fbab435c96b188eb9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
jQuery(document).ready(function ($) { | |
$(".btn_schedule").click(function() { | |
var selected_id = 1; | |
var schedule = {"Monday":{"morning":"8:00 am","afternoon":"1:00 pm"}, | |
"Tuesday":{"morning":"8:00 am","afternoon":"1:00 pm"}}; | |
var myJSON = JSON.stringify(schedule); | |
save_clinic_schedule(selected_id,myJSON); | |
}); | |
//ajax script to save JSON to Database | |
function save_clinic_schedule(selected_id,schedule_container){ | |
$.ajax({ | |
type:"POST", | |
data:{ | |
action:'save_clinic_schedule', | |
selected_id:selected_id, | |
schedule_container:schedule_container | |
}, | |
url : myAjax.ajaxurl, | |
success:function(data) | |
{ | |
//alert your json if you want to verify it's working | |
alert(data); | |
} | |
}) | |
} | |
}); | |
</script> | |
<?php | |
add_action('wp_ajax_save_clinic_schedule','save_clinic_schedule'); | |
add_action('wp_ajax_nopriv_save_clinic_schedule','save_clinic_schedule'); | |
function save_clinic_schedule(){ | |
// your selected table | |
global $wpdb; | |
$table = $wpdb->prefix . 'ohr_clinic'; | |
$data['schedule'] = $_POST['schedule_container']; | |
$clinic_id = $_POST['selected_id']; | |
//to check if json is not empty will be used for alert later. | |
echo $_POST['schedule_container']; | |
$wpdb->update( $table, $data, array( 'clinic_id' => $clinic_id) ); | |
wp_die(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment