user3011784 user3011784 - 7 months ago 43
Javascript Question

jquery AjaxSubmit function how to get result from the form page to display

I'm trying to understand how to use ajaxSubmit() properly and I'm having some difficulties. I want to submit my form with ajax and after change the container value to the result echo by the form. I have an HTML form

<form action="contact.php" method="post" id="contact_form" >
<div id="form-box">
<input type="text" name="name" maxlength="40" >
<input type="submit" name="contact" value="SUBMIT" />

And then in JS I use the following code to submit the form to

$(document).ready(function() {
var options = {
success: showResponse

$('#contact_form').submit(function() {
return false;


function showResponse(responseText) {
$("#form-box").html("Thank you message");

Now, the
changes with my "Thank you message" ... but how do I grab what is echo from contact.php after the script is executed?

I'm not sure how to do this and make it work.


It would be included in the responseText, assuming your PHP file is actually outputting something.

Try updating your function to

function showResponse(responseText)  { 
 $("#form-box").html("Thank you message"+responseText);