php - AJAX 哈希提交表单

标签 php jquery ajax

我很确定它与我的带有 ajax 哈希 url 的 core.js 文件有关。但是我正在尝试提交表格,但它并没有像我希望的那样提交。这是 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

点击链接“发表评论”,然后您将输入信息,然后点击评论,但它只是刷新,而不是提交。

我采取的解决步骤是在评论文件中,在表单操作字段中,我插入了标签 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> 

最佳答案

我注意到您没有在文件“comment.php”上设置 ajax 类型。

你需要...

 $.ajax({
            type: 'POST',
        url: 'comment_ajax.php',
        data: { form_name: name, form_comment: comment },
        success: function(data) {
            $('#new_comment').prepend(data);
                        // close modal box
            // do other shit
            // kthnxbai
        }
    });

如果未指定类型,则默认为不会发布数据的 GET 请求。 :)

关于php - AJAX 哈希提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13372065/

相关文章:

php - 如何通过php数组一条一条更新mysql中的每条记录?

c# - 使用 Kendo Grid,如何更改工具栏中 "Create"按钮上的文字?

javascript - 将多组参数分配给 jQuery 函数

jquery - 为什么在 DataTable() 上调用 ajax.reload() 返回未定义?

javascript - 如何在javascript中获取动态创建的文本框值

php - array(...) 构造中的条件元素

php - 递归文件搜索 (PHP)

javascript - asp.net mvc 中的 javascript 变量出现问题

php - 我应该在 CouchDB/Ajax 应用程序中使用 PHP 中的数组还是对象?

php - 遍历多维数组