过帐表单数据Jquery

Posting form data Jquery

本文关键字:Jquery 数据 表单      更新时间:2023-09-26

我正在尝试构建一个移动应用程序,但在获取Jquery/Javascript的基础知识时遇到了一些困难。我正在努力制作它,这样我就可以在输入字段中键入我想要的任何值,然后发布它,它会发布在上面,允许我在输入字段键入更多,它会在最后一个帖子上面发布。

这是我迄今为止的代码。不知道下一步该去哪里,或者我是否朝着正确的方向前进。

 <!DOCTYPE HTML>
    <HTML>
     <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
        $('#commentForm').submit(function(){ //listen for submit event
        $.each(params, function(i,param){
            $('<input />').attr('type', 'show')
                .attr('value', param.value)
                .appendTo('#commentForm');
        });

        return true;
    });

    </script>
    <BODY>
    <form id="commentForm" method="POST">
        <textarea  cols="30" rows="6" name="comment" title="Enter a comment">
        </textarea>
        <input type="submit" value="Post"/>
        <input type="reset" value="Reset"/>
    </form>
    <div id="box">
    </div>
    </BODY>
    </HTML>

给提交按钮一个名为"提交"的id

    function onSuccess(data, status) {
        data = $.trim(data);
           //make a div with id "notification" before running this code
        $("#notification").html(data);
        $.mobile.hidePageLoadingMsg(); //used on jquery mobile to hide a loader
    }
    function onError(data, status) {
        data = $.trim(data);
        $("#notification").html(data);
        $.mobile.hidePageLoadingMsg(); //used on jquery mobile to hide a loader
    }
    $("#submit").click(function() {
        $.mobile.showPageLoadingMsg(); //used on jquery mobile to show a loader
        var formData = $("#commentForm").serialize(); //get all data from form
          //do the POST thingies
        $.ajax({
            type: "POST",
            url: "url_to_your_php_interpreter",
            cache: false,
            data: formData,
            success: onSuccess,
            error: onError
        });
        return false;
    });

我正在使用此脚本登录用户。PS:您将从php解释器"回显"的所有内容都将显示在div上,id为"notification",您将(可能)创建