I currently have the following code:
home.php
<form name='myformname' id='myformid'>
<input type='text' name='mytext1' value='abc'>
<input type='text' name='mytext2' value='123'>
<input type='submit' value='Submit'>
</form>
<div id='textone'></div><div id='texttwo'></div>
_home.php
$arr = array( 'textone' => $_POST['mytext1'], 'texttwo' => $_POST['mytext2'] );
echo json_encode( $arr );
ajax.js
jQuery('#myformid').live('submit',function(event) {
$.ajax({
url: '_home.php',
type: 'POST',
data: $('#myformid').serialize(),
success: function( data ) {
alert(data);
}
});
return false;
});
Output to submit:
{"textone":"abc","texttwo":"123"}
Question
I want to load mytext1 value textone DIV and mytext2 into texttwo DIV using json data in _home.php
Hint: I am using this answer to accomplish the same task in the click click event. But how to do this when submitting the form?
thank
source
share