【发布时间】:2018-09-28 02:56:53
【问题描述】:
我试图将我的数组从控制器传递给我的 ajax 结果,然后使用结果来确定我是否应该显示某些 div。下面是我的 PHP 控制器。
public function actionCheckUser(){
$user = $this->user;
$has_name = $user['realname'] != '' ? 'name_tab' : 'none';
$has_mobile_verified = $user['mobilestatus'] == 1 ? 'mobile_tab' : 'none';
$check = array($has_name, $has_mobile_verified);
$data['result'] = $check;
echo json_encode($data);
}
这是我的 ajax
var myarray = new Array();
$.ajax({
url: "/member/CheckUser",
type: "POST",
success: function(data){
var myarray = $.parseJSON(data);
array = myarray.result;
myarray = array.split(',');
},
error: function (xhr, ajaxOptions, thrownError) {
//alert(xhr.status);
alert(thrownError);
},
//dataType:"json"
});
$(".tab").each(function(){
if(jQuery.inArray($(this).attr('id'), myarray) !== -1){
var id = $(this).attr('id');
$('#'+id).removeClass('tab');
$('#'+id).hide();
}
});
我无法将它作为数组返回,它也没有对我的 div 做任何事情...
我正在尝试使用结果来确定要隐藏和显示哪个 div。
【问题讨论】: