1

目前我在使用 jquery 表单插件时遇到问题。部分原因是我需要更改表单提交的哈希值。这是我在做什么的基础:

$(document).ready(function()  {
$('#search').ajaxForm({
target: '#pageContent',

success: function()  {
$('#pageContent'); //this is all i need to 'ajaxify' this form
var hash = 'query='+encodeURI(document.getElementById('query').value);
window.location.hash = hash;
}
});
});

现在发生的事情是我能够更改哈希值,但我的表单不再是“ajaxify”本身,而是我只是得到一个空白页..

我究竟做错了什么?

4

2 回答 2

2

由于没有人有合适的答案,我设法破解了我的 jquery.history.js 实现,以允许通过 ajax 进行搜索。代码如下:

$(document).ready(function() { 
// bind form using ajaxForm 
$('#search1').ajaxForm({ 
    // target identifies the element(s) to update with the server response 
    target: '#pageContent', 

    // success identifies the function to invoke when the server response 
    success: function() { 
        $('#pageContent'); 
        var hash = '#search.php?term='+($('#query').val()+'&submit=Submit').replace(/ /g, '+');
        update(window.location.hash = hash);
    } 

}); 

});

我还替换了搜索中的空格以包含+标志..也许这会对某人有所帮助。

于 2011-05-05T19:21:03.147 回答
1

尝试添加一个实际的哈希,用 表示#

$(document).ready(function()  {
  $('#search').ajaxForm({
    target: '#pageContent',    
    success: function() {
      var hash = '#query='+encodeURI($('#query').val());
      window.location.hash = hash;
    }
  });
});
于 2011-04-22T22:43:08.373 回答