weixin_33739523 2012-03-17 06:40 采纳率: 0%
浏览 53

如何修正jQuery $ .post结果条件?

我通过在jQuery网站中添加条件来修改此代码,但无论怎么改,它总是进入第一个“ if”——如何才能修正这个错误?

<script>
/* attach a submit handler to the form */
$("#searchForm").submit(function(event) {

/* stop form from submitting normally */
event.preventDefault(); 

/* get some values from elements on the page: */
var $form = $( this ),
    term = $form.find( 'input[name="s"]' ).val(),
    url = $form.attr( 'action' );

/* Send the data using post and put the results in a div */

**//the condition doesn't work here. It always get into the first "if". Why?**
$.post( url, { s: term },
  function( data ) {
      if (var content = $( data ).find( '#content' )) {
          console.log('One or more results were found');
      } else {
          console.log('no result');
      }
  }
 );
});
</script>
  • 写回答

3条回答 默认 最新

  • weixin_33719619 2012-03-17 06:43
    关注

    because you are making an assignment in the condition. it's always returned true. but if it was something like

    if(data!="")
    

    then it would be a condition.

    评论

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗