Search code examples
jqueryjquery-forms-plugin

JqueryForm result in a div


I am using the jQuery Form plugin API to submit a form. It is submitting in the background, but how do I show this result (actionpage.php) in a div (with id posthere) as shown below.

<form id="myForm" action="actionpage.php" method="post"> 
    Name: <input type="text" name="name" /> 
     <input type="submit" value="Submit Comment" /> 
</form>
<script>
$('#myForm').ajaxForm();
</script>

<div id="posthere" ></div>

Solution

  • Please try following code.

    $("#myForm").ajaxForm({
        success: function(res, status, xhr, form) {
            // This will show the direct res over here, you can format it as per your need.
            $('#posthere').html(res);
        }
    });