Trying to get PHP responce on ajax
Trying to get PHP responce on ajax
here I am trying to update the MSQL table using jquery , both PHP code and jquery script is written on the same page,
the code working fine to update my tables but the response msg is not getting by the ajax so it always shows me the default message "Some problem occurred, please try again.".
here is the code:
<!-- HTML code to display msg -->
<p class="statusMsg_post"></p>
<script>
$(document).ready(function(){
$('#btn_publish').click( function(){
var obj_post_postID="<?php echo $post_id; ?>";
var publish_post="publish";
$.ajax({
type:'POST',
// url:'post_view.php',
data:{ "post_status_update":publish_post,
"obj_post_status":obj_post_postID,
},
success:function(res){
if(res=='ok'){
$('.statusMsg_post').html('<span style="color:green;">Post has been '+publish_post+' sucessfully</span>');
}else{
$('.statusMsg_post').html('<span style="color:red;">Some problem occurred, please try again.</span>');
}
}
});
});
});
</script>
//my PHP code to update my table
<?php
// require_once('../../inc/db-connect.php');
if(isset($_POST['post_status_update'])){
$temp_publish_post=$_POST['post_status_update'];
echo $bj_post_postID=$_POST['obj_post_status'];
$obj_post_status_query ="UPDATE `objection_report` SET `obj_status` = '$temp_publish_post' WHERE `objection_report`.`obj_post_id` = $bj_post_postID;";
$obj_post_status_query .="UPDATE `post` SET `status` = '$temp_publish_post' WHERE `post`.`post_id` =$bj_post_postID ;";
if(mysqli_multi_query($con, $obj_post_status_query)){
echo "ok";
die;
}
}
?>
all the above codes are on the same page
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.