get content of a div from a variable using jQuery

Posted by devdarsh on Stack Overflow See other posts from Stack Overflow or by devdarsh
Published on 2010-05-28T06:44:42Z Indexed on 2010/05/28 6:51 UTC
Read the original article Hit count: 213

Filed under:

i am building a php form with ajax and i am submitting the form variables to the same page where the form resides. my validating code looks like if($valid){ echo "<div id='retmsg'>Your message has been submitted successfully</div>"; } else { echo "<div id='retmsg'>An error occured!</div>"; } My ajax code

function form_submit() {
 $('#response').html('Loading...').fadeIn();
$.ajax({
    type: "POST",
url:  "<?php $_SERVER['PHP_SELF']; ?>",
data: "title=" + $('#title').val() + "&content=" + $('#contents').val(),
success: function(html){
var message = $("#retmsg").html(html);
alert(message);
  }

}); 
}

i need to alert the contents of div id "retmsg". But the alert shows me like "[Object Object]". Please help me...

© Stack Overflow or respective owner

Related posts about jquery-ajax