thinkphp里面的ajax关于表单提交的写法

<script type="text/javascript">
$(document).ready(function(){

$("#J_index_btn").bind('click',function(){

var name = $('#name').val();
var phone = $('#phone').val();
var identification = $('#identification').val();
var height = $('#height').val();
var weight = $('#weight').val();
var age = $('#age').val();
var foodcontent = $('#foodcontent').val();

$.ajax({

url: '/SigninfoAction/register',
type: "post",
data:{

'name':name,
'phone':phone,
'identification':identification,
'weight':weight,
'height':height,
'age':age,
'foodcontent':foodcontent,

},
dataType:'json',
error:function(){
alert(msg);

alert("服务器忙,请稍候再试");

},
success:function(data){

if(data.error==0){

alert('报名成功 ! 我们会马上联系您并帮您安装!');

window.location.reload();

}else{
alert('报名失败 ! 请重试!');
}

}

});

});

});
</script>
这段ajax表单提交 始终都是跳到error function() 点提交就跳出“服务器忙,请稍后重试” ,就是没进到提交的那段 ,也不太清楚url该怎么写才是对的...求大神指教...

<html>
<head>
<script type="text/javascript" src="__PUBLIC__/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
  $(function(){
    $('input:button').click(function(){
      var $title=$('input[name="title"]').val();
      var $message=$('input[name="message"]').val();
      $mess=$('#mess');
      $.getJSON('__URL__/add',{title:$title,message:$message},function(json){
        //alert(json);return false;
        if(json.status==1){
          $mess.slideDown(3000,function(){
            $mess.css('display','block');  
          }).html('标题为'+json.data.title+'信息为'+json.data.message);  
        }else{
          $mess.slideDown(3000,function(){
            $mess.css('display','block');  
          }).html('信息添加失败,请检查');  
        }    
      });
    })  
  })
</script>
</head>
<body>
<div style="display:none; color:red;" id="mess"></div>
<form action="" method="get">
 æ ‡é¢˜ï¼š<input type="text" name="title" /><br />
 ä¿¡æ¯ï¼š<input type="text" name="message" /><br />
    <input type="button" value="提交" />
</form>
</body>
</html>

上面是前段代码


MessageAction.class.php页面代码如下:

<?php
class MessageAction extends Action{
   
  function index(){
    $this->display();  
  }
   
  function add(){
    //ajaxReturn(数据,'提示信息',状态)  
    $m=M('message');
    if($m->add($_GET)){
      $this->ajaxReturn($_GET,'添加信息成功',1);
    }else{
      $this->ajaxReturn(0,'添加信息失败',0);  
    }
  }
  
}
?>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-11-09
先看下这个url /SigninfoAction/register
在regiter这个方法里直接输出echo 'come'; 通过firebug类似的工具进行查看,是否输出的是come,
还有一点就是你的php文件的最后面不要有多的换行和空白符。本回答被提问者和网友采纳
相似回答