thinkphp5 jquery ajax异步提交问题

时间:2021-10-27 13:33:37
                            前台代码:
                            <form enctype="multipart/form-data" action="{:url()}" method="post">
                            <input type="file" name="image">
                            <select class="form-control m-b" name="folder">
                                <option value="1">网络维护</option>
                                <option value="2">系统管理</option>
                                <option value="3">项目工程</option>
                                <option value="4">软件开发</option>
                            </select>  
                            <input type="submit" class="btn btn-primary btn-block" value="上传">
                            </form>
                                <script>
                                $("form").submit(function(){
                                $.post("action",data,success,'json');;
                                return false;
                                function success(data){
                                if(data.success){                           
                                layer.msg( data.msg, {icon: 1, time: 1500} );
                                }else{
                                layer.msg( data.msg, {icon: 2, time: 1500} );
                                }
                                }
                                });
                               </script>
                              后台代码:
                             $result="上传成功!";
    return json_encode(array('success'=>1,'msg'=>$result));

3 个解决方案

#1


数据能够回调, thinkphp5 jquery ajax异步提交问题
为什么触发不了回调函数success

#2


$.post("action",data,success,'json');;  看看 action是不是该改成提交地址,data是不是没有声明;

#3


echo json_encode(array('success'=>1,'msg'=>$result));

#1


数据能够回调, thinkphp5 jquery ajax异步提交问题
为什么触发不了回调函数success

#2


$.post("action",data,success,'json');;  看看 action是不是该改成提交地址,data是不是没有声明;

#3


echo json_encode(array('success'=>1,'msg'=>$result));