JQuery Posting Form Data

I am trying to create a mobile app, but I am having problems generating JQuery / Javascript. I am trying to make it so that I can enter whatever value I want in the input field and then post it, it would post above and allow more to be entered in the input field and it will be placed above the last post.

Here is my code. Dead end where to go next, or if I go 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>

      

0


source to share


1 answer


Give the submit button the id "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;
    });

      



I am using this script to login. PS: anything you will "echo" from the php interpreter will be shown on a div with id "notification" with which you (possibly) create

+1


source







All Articles