报错部分为图中红线部分
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');
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…