jui结合ajax非表单提交刷新页面

这个跳转,研究了好久才弄清楚!希望大家能用到吧!

方法1:

直接用ajax请求,然后刷新本页

   <img src="/static/admin/img/delete_icon.png" class="delete-prize" onclick="prizedel()" id="prize-del" style="display:none;">

    function prizedel()
    {
        if ($('.prizename-list').find("li").length > 2) {
            var config = confirm("确认删除该红包吗?");
            if (config == true) {
                $.ajax({
                    url: '/admin/delMred',
                    type: 'post',
                    data: {
                        level: level
                    },
                    dataType: 'json',
                    success: function(data) {
                        if(data.statusCode ==200 ){
                            alertMsg.correct(data.message);
                            //$.pdialog.reload('/admin/red_get',{data:{}, dialogId:'red_get', callback:null});
                            navTab.reload("/admin/red_get", {navTabId: 'red_get'});
                        }else{    
                            alertMsg.warn(data.message);
                        }  
                    },
                    error: function() {
                        alertMsg.warn('删除失败');
                    }
                });
            }
        } else {
            alertMsg.warn("至少有一个红包")
        }
    }

方法2:

用a链接操作:

   <a id="red_del" href="/admin/delMred"  target="ajaxTodo" title="确定要删除吗" rel="" mask="true" fresh="true"><img src="/static/admin/img/delete_icon.png" class="delete-prize" id="prize-del" style="display:none;"></a>

    //删除红包设置
    public function delMred()
    {
        $level = intval(input("param.level"));

        //测试数据
        //$level = 1;

        if(empty($level)){
            $result['message'] = "奖品参数出错~";
            $result['statusCode'] = 300;
            return json($result);
        }
        $info = Db::table('mred')->where(['level'=>$level])->value('id');
        if(empty($info)){
            $result['message'] = "数据不存在~";
            $result['statusCode'] = 300;

            return json($result);
        } 

        //直接删除操作
        $res = Db::table('mred')->where(['level'=>$level])->delete();

        if($res !== false){
            $result['message'] = "删除成功~";
            $result['statusCode'] = 200;
            $result['navTabId'] = "red_get";
        }else{
            $result['message'] = "网络错误,请重试~";
            $result['statusCode'] = 300;
        }
        return json($result); 
    }

 

posted @ 2019-01-24 14:52  瑛雄  阅读(301)  评论(0编辑  收藏  举报