I need to call a php function from I suspect an ajax call. I have ckeditor and need to trap any keyboard movement and think onchange will do that. I then need to run a function to stop a timeout from happening, as I suspect the program can timeout if the user is staying in the editor too long.
<textarea required cols='80' rows='9' class='ckeditor' name='email_text_editor' id='email_text_editor1' placeholder='Body text' onchange='updateTimer(this.value);'><?PHP print $email_subs_rem; ?> </textarea>
function updateTimer(myValue) {
//sessionTimeoutUpdate();// php function
//console.log(myValue);
//$.ajax({
// type: "GET",
// url: "dummy.php",
// data: "mainid =" + id,
// success: function(result) {
// $("#somewhere").html(result);
// }
//});
}
</script>
You can do something like this...
function updateTimer(myValue) {
//sessionTimeoutUpdate();// php function
console.log(myValue);
$.ajax({
type: "GET",
url: "dummy.php",
data: {"mainid =" + id, action : "updateSession"},
success: function(result) {
$("#somewhere").html(result);
}
});
}
PHP file
<?php
if(isset($_GET['mainid'])){
if($_GET['action']== "updateSession"){
sessionTimeoutUpdate();//function you wanna call
}
}
function sessionTimeoutUpdate(){
//Do your task here
//After done
echo "done";
}
?>
Since there is no way you can directly call a php function at client side without request, AJAX is very useful here.
Comment down for any queries.