jQuery.ajax方法无需刷新即可获取数据

时间:2012-07-10 11:36:19

标签: jquery ajax methods

我有这个问题,我喜欢做的是没有刷新。 我想要的是,当我搜索然后按回车时,播放列表不应该刷新。

我的网页的网页示例为http://cocopop12.site11.com/v1.7/index.php

我的jquery脚本是否正确?我是否需要使用ajax以便页面不会刷新?

$(function(){
$('input[name="searchsubmit"]').click(function(e) {         
    e.preventDefault();
    var qS = $('#qsearch').val();

    $.ajax({
        type:"GET",
        url:"",
        data: qS,
        dataype: 'html',
        success: function(data){
           $('input#qsearch').html(data);
            return false;
        }
    })
}); 
});

按钮是

<div class="search">
<form id="quick-search" action="" method="get">
<p>
<label for="qsearch">Search:</label>
<input class="tbox" id="qsearch" type="text" name="q" value="Keywords" title="Start typing and hit ENTER" onblur="if(this.value=='') this.value='Keywords';" onfocus="if(this.value=='Keywords') this.value='';" />
<input class="btn" alt="Search" type="image" name="searchsubmit" title="Search" src="./css/search.gif" />
</p>
</form>
</div>

感谢您的时间。

1 个答案:

答案 0 :(得分:3)

尝试success而不是done(),您无法将ajax调用data传递给done()方法:

    $.ajax({
        type:"GET",
        url:"",
        data: qS,
        datatype: 'html',
        success: function(data){
           $('input#qsearch').html(data);
        }
    }).done(function() {
        alert('done')
    })