jquery:在更改事件后显示数据

时间:2010-06-11 04:40:04

标签: jquery ajax

我有这段代码:

<script>
$("#mod").change(function() {
 var matches=str.match(/(EE|[EJU]).*(D)/i);
         $.ajax({
                  type="post",
                  url="process.php",
                  data="matches",
                  cache=false,
                  async=false,
                  success= function(res){
                         $('#rslt').replaceWith("<div id='value'><h6>Tuner range is" + res + " .</h6></div>");
                         return this;
                 }
         });
   return false;
});
 </script>

我希望这段代码能正常显示结果......我的错是什么?

2 个答案:

答案 0 :(得分:2)

删除return s

并格式化为(:而不是=

         $.ajax({
                  type:"post",
                  url:"process.php",
                  data:"matches=" + matches,
                  cache:false,
                  async:false,
                  success: function(res){
                         $('#rslt').replaceWith("<div id='value'><h6>Tuner range is" + res + " .</h6></div>");
                         // return this; <<--- remove that too...
                 }
         })

如果您希望将matches作为数据传递,请使用data:"matches=" + matches, ...

$_POST['matches']是通过PHP获取值的方法

答案 1 :(得分:0)

<script>
$("#mod").change(function() {
 var matches=str.match(/(EE|[EJU]).*(D)/i);
         $.ajax({
                  type:"post",
                  url:"process.php",
                  data:"matches="+matches,
                  cache:false,
                  async:false,
                  success: function(res){
                         $('#rslt').replaceWith("<div id='value'><h6>Tuner range is" + res + " .</h6></div>");

                   }
         });
  });
 </script>