我很确定它与我的core.js文件和ajax哈希网址有关.但是我正在尝试提交表单,但它并没有像我想要的那样提交.这是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
点击链接“发表评论”,然后你将输入信息,然后点击评论,但它只是刷新,但不提交.
我用来解决它的步骤是在注释文件中,在表单操作字段中,我插入了标记名称=“#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();
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。