发布表单数据Jquery

时间:2012-02-02 11:28:57

标签: javascript jquery post

我正在尝试构建一个移动应用程序但是在获取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>

1 个答案:

答案 0 :(得分:1)

为提交按钮提供一个名为“提交”的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解释器“回应”的所有内容都将显示在id为“notification”的div上,你将(可能)创建

相关问题