Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

thinkphp ajax提交信息,status code显示404 not found

报错部分为图中红线部分
图片描述

图片描述
html部分

 <div >
    <div>  

    <div>
         <input type="text" id="js-mobile"  name="mobile"  >
   </div>
    <div>
      <input type="text" id="js-username" name="username" >
   </div>
    <div >
          <button id="submit">提交</button>
     </div>
</div>
</body>

<script src="//cdn.bootcss.com/jquery/1.7.1/jquery.min.js"></script>
<script>
(function($){
$("#submit").on('click',function () {
    var postdata = {
        'mobile':$("#js-mobile").val(),
        'username':$("#js-username").val(),
    };

       
        $.post('__CONTROLLER__/handle',postdata,function(data){
            if(data.status){
                alert("提交成功");
            }else{
                alert("提交失败");
            }
        },'json');
     

    });
})(jQuery);
</script>

controller

<?php
namespace HomeController;
use ThinkController;
class ActivityController extends Controller {
    public function handle(){
        if(!IS_AJAX) halt('页面不存在');
        $data = array(
            'username' => I('username'),
            'mobile' => I('mobile'),
            'ctime' => time()
            );
        //print_r($data);
        if(M('activity')->data($data)->add()){
            $data['status'] = 1;
            $this->ajaxReturn($data,'json');
        }else{
            $this->ajaxReturn(array('status'=>0),'json');
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Ajax时,如果非开发模式(APP_DEBUG==false),程序存在错误,就会提示404。

#修改 index.php中的 APP_DEBUG = ture 即可看到报错信息
define("APP_DEBUG", true );

图片描述
图片描述

比如数据库密码错误:
SQLSTATE[HY000] [1044] Access denied for user 'XXX'@'' to database 'XXX'
2017-3-13 答案已经修改,以下为原答案:
================================================
404 文件不存在。

你确定 你的 index.php 在 /order/index.php 而不是在 /index.php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...