发布表单数据Jquery [英] Posting form data Jquery

查看:71
本文介绍了发布表单数据Jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个移动应用程序,但是在获取Jquery/Javascript的基础方面遇到了一些麻烦. 我正在尝试使其能够在输入字段中键入所需的任何值,然后将其发布,它将在上方发布,并允许我在输入字段中键入更多内容,并将其发布在最后一个帖子的上方.

I am trying to build a mobile app but am having some trouble getting the basics of 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>

推荐答案

为提交按钮提供一个名为"submit"的ID

Give the submit button an id called "submit"

    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",您将(可能)创建

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

这篇关于发布表单数据Jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆