如何修正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>
查看全部
weixin_33739523
weixin_33739523
2012/03/17 06:40
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

3个回复