将数据发布到sql数据库而不重新加载页面

jak*_*123 3 php jquery

问题是我无法在没有重新加载的情况下在我的数据库中插入数据我已经测试了它没有note_sql.js和我的note_sql.php工作正常但是我的js文件中似乎有问题,如果有些身体可以指向我正确的方向它会很棒

的index.php

    <form id="noteform" action="note_sql.php" method="POST">
    <input type="text" name="note"></input>
    <input id="sub" type="submit" value="Save Note" />
    </form>
    <span id="result_note"><span>
   <script type ="text/javascript" src="jquery/note_sql.js"></script>
Run Code Online (Sandbox Code Playgroud)

note_sql.js

$("#sub").click(function(){

var data = $("#noteform: input").serializeArray();
$.post($("#noteform").attr("action"),data,function(info){$("result_note").html(info); });
    clearInput();
}); 

$("#noteform").submit(function(){
    return false;
});

function clearInput(){
    $("#noteform :input").each(function(){
        $(this).val('');
    });
}
Run Code Online (Sandbox Code Playgroud)

小智 5

使用Jquery Ajax,下面给出了工作代码:请在注释表单元素中添加ID:

<pre>
      <script>
            $(document).ready(function () {
                $("#sub").click(function () {

                    var name = $("#note").val();
                    var message = $("#message").val();

                    $.ajax({
                        type: "post",
                        url: "note_sql.php",
                        data: "name=" + name,
                        success: function (data) {
                            alert(data);
                        }

                    });

                });
            });
        </script>
</pre>
Run Code Online (Sandbox Code Playgroud)