简体   繁体   English

发布表单数据Jquery

[英]Posting form data Jquery

I am trying to build a mobile app but am having some trouble getting the basics of Jquery/Javascript. 我正在尝试构建一个移动应用程序,但是在获取Jquery / Javascript的基础方面遇到了一些麻烦。 I am trying to make it so I can type in any value I want into the input field and then post it, it would post above and allow me to type more into the input field and it would post above the last post. 我正在尝试使其能够在输入字段中键入所需的任何值,然后将其发布,它将在上方发布,并允许我在输入字段中进行更多键入,并将其发布在最后一个帖子的上方。

Here is my code so far. 到目前为止,这是我的代码。 Stumped where to go next or if I am going in the right direction. 困扰着下一步去哪里,或者我朝着正确的方向前进。

 <!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>

Give the submit button an id called "submit" 为提交按钮指定一个名为“ submit”的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;
    });

I'm using this script to login an user. 我正在使用此脚本登录用户。 PS: everything you will "echo" from php interpreter will be shown on div with id "notification" wich you will (probably) create PS:您将从php解释器中“回显”的所有内容都将在ID为“ notification”的div上显示,您将(可能)创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM