【发布时间】:2020-04-20 09:33:40
【问题描述】:
我有 2 个条件像这样以 json 格式返回
public funtion do_upload{
//1st
return json_encode(['upload_success' => 'Successfully import ' . $count_validEntries . ' document]);
//2nd
return json_encode(['upload_error' => 'Your document is not valid, at row '. $implode_err. 'Please use given data']);
}
我的 Ajax 调用
$("#upload_btn").on('click', function(){
var mydata = new FormData(document.getElementById("form_upload"));
$.ajax({
type : "POST",
data: mydata,
contentType: false,
dataType : "json",
url : "<?php echo base_url();?>/C_MRCR_A/do_upload",
cache: false,
processData: false,
beforeSend:function(){
},
success:function(response){
console.log('succ ',response);
},
error:function(xhr, status, error){
},
complete:function(){
// do nothing for now
}
});
});
如果'upload_success' 我想让alert 成功,如果'upload_error' 使用上面的响应,我想警告错误?还是有其他方法?
【问题讨论】:
-
您是否将此响应发送到 Ajax 调用?
-
@AlokMali 对,我已经编辑了我的问题
-
您希望在 HTML 中的什么位置显示警报?
-
当我点击
upload_btn后,如果这就是你的意思
标签: php json jsonresponse