tp5中使用Ajax

浏览:8123 发布日期:2018/07/20 分类:求助交流 关键字: Ajax tp5 前端
控制器部分public function test()    
    {
        $mess = input('mess');
        $id = input('id');
        if(request()->isAjax())
        {        
            
            if($mess == '123'){  
                return json("ajax成功!".$mess."---".$id);die;
            }else{  
                return json("你输出的是其他值:".$mess."---".$id);
            }
        }
        else{
            return $this->fetch('test');
        }
    }
前端<!DOCTYPE html>
<html>
<head>
<script src="__PUBLIC__/static/admin/js/jquery-1.10.2/jquery.min.js"></script>
    <script>
    function ajaxPost(){
        $(document).ready(function(){
            $("button").click(function(){
                $("div").load("{:url('/Admin/Map/test')}");
            });
        });
    }
    </script>
</head>
<body>
 <form id="myform"><!--这里给表单起个id用于获取表单并序列化-->   
    <input type="text" name="mess" value="123"/>  
    <input type="text" name="id" value="123" />   
 </form>
 <button onclick="ajaxPost()">Ajax</button>
<!-- <button>获取外部内容</button> -->
 <div id="content"> 
 </div>  
</body>
</html>
为什么它接收不到前端传过去的数据?
最佳答案
评论( 相关
后面还有条评论,点击查看>>