目前我在我的控制器中,我已經在控制器中進行了檢查。基本上檢查特定欄位的值是否為 0。現在如果它是 0,我想通過我的控制器顯示一個警報彈出視窗。為此,我嘗試了以下代碼:
public function status($status){
if($this->input->post('id')){
foreach($this->input->post('id') as $key => $id):
$check_emirate = $this->listings_model->check_emirate($id);
if($check_emirate->emirate == 0){
echo "<script>alert('This card was not approved.');</script>";
}else{
$data=array('status'=>$status); $updated=$this->listings_model->update($data,array(),$id);
}
endforeach;
}
return true;
}
現在它正在進入我的 if 條件,但它沒有顯示彈出視窗。
這是我為啟用此功能而進行的 AJAX 呼叫:
$(".status").click(function(e) { chagestatus($(this)); }
function chagestatus(obj){
if($('.chkbx').is(':checked') == true){
$.ajax({
type: "post",
dataType: "json",
async:false,
url: "<?php echo site_url('listings/status'); ?>/" obj.data('val'),
data: $(".chkbx:checked").serialize(),
success: function(result) {}
});
}
}
我在這里嘗試過的另一件事是以這種方式使用 json_encode :
if($check_emirate->emirate == 0){
$data = "<script>alert('This card was not approved, Thanks.');</script>";
echo json_encode($data);
}
success: function(result) {
result = JSON.parse(result);
}
但這也沒有得到任何回應。
uj5u.com熱心網友回復:
如果您的控制器中的功能運行良好,那么您需要將結果從服務器附加到您的 DOM:
success: function(result) {
$('body').append(result);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/431269.html
標籤:javascript php jQuery 阿贾克斯 代码点火器
