forms - 具有哈希更改功能的 jquery 表单插件

标签 forms jquery fragment-identifier

目前我在使用 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”本身,而是我只是得到一个空白页面..

我做错了什么?

最佳答案

由于没有人有合适的答案,我设法破解了 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);
    } 

}); 

});

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

关于forms - 具有哈希更改功能的 jquery 表单插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5760726/

相关文章:

forms - Http Basic Auth 的登录表单

php - 获取相关表单字段的列表作为关联数组

forms - 提交表单后 SEO Url 没有改变

javascript - 插入 HTML 时 URL 变形

jquery - 将 jQuery UI 颜色选择器 slider 转换为 jQuery Mobile 版本

jquery - 使用 will_paginate Rails 4 的 Ajax 请求

url - 为什么维基百科在其 URL 片段中使用修改后的百分比编码?

php - 无法通过 jquery 更改表单操作

fragment-identifier - URL 中片段标识符的有效字符列表?

url - 如何从服务器端获取 Url Hash (#)