我确信这与我的core.js文件和ajax散列url有关。但我试图提交一份表格,但它并不像我希望的那样提交。这是core.js文件:
// call init
$(init);
function init() {
ajax_page_handler();
page_load($(window.location).attr("hash")); // goto first page if #! is available
}
function page_load($href) {
if($href != undefined && $href.substring(0, 2) == '#/') {
// replace body the #content with loaded html
$('#content').load($href.substring(2), function () {
$('#content').hide().fadeIn('slow');
});
}
}
function ajax_page_handler() {
$(window).bind('hashchange', function () {
$href = $(window.location).attr("hash");
page_load($href);
});
// this allow you to reload by clicking the same link
$('a[href^="#/"]').live('click', function() {
$curhref = $(window.location).attr("hash");
$href = $(this).attr('href');
if($curhref == $href) {
page_load($href);
}
});
}
现场观看结束于www.krissales.com。表格在这里:http://www.krissales.com/#/media/5.Testing-1
点击链接“post comment”,然后输入信息,然后点击comment,但它只是刷新,但不提交。
我已经采取了一些步骤来解决这个问题,在comment文件的form action字段中,我插入了标记
name="#content"
,因为这是我提交给的div的名称。原来的东西在http://blog.krissales.com/article/7.Testing-3-man上(在那里你可以发表评论,它会起作用)
但显然它不起作用。你们知道我做错了什么吗?提前谢谢你的帮助!
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "simple"
});
</script>
<form action="#/media/article.php" name="#content" method="POST">
Name:
<br />
<input type="text" name="name" class="userpass"/>
<br /><br />
Comment:
<br />
<textarea id="elm1" name="comment" rows="7" cols="30" style="width: 500px;">
</textarea>
<br />
<input type="submit" name="submit" value="Comment" class="button" />
<input type="reset" name="submit" value="Reset" class="button" />
</form>
最佳答案
当前的core.js处理url散列中的更改,并使用散列重新路由任何链接,以便将该相对路径加载到#content
。缺少的是重定向表单提交以执行相同操作的代码(将此添加到ajax_page_handler
):
$('form').live('submit', function(e) {
var $action = $(this).attr('action');
if($action.substring(0, 2) == '#/') {
// replace the #content with result of the form post
$.ajax({
url: $action.substring(2),
type: $(this).attr('method'),
data: $(this).serialize(),
success: function(data) {
$('#content').html(data);
$('#content').hide().fadeIn('slow');
}
});
// stop the real form submit from happening
e.preventDefault();
}
});