PHP: Problem submitting form in AJAX/JSON?

currently I have following code:


<form name="myformname" id='myformid'>
    <input type="text" name="mytext1" value="abc">
    <input type="text" name="mytext2" value="123">
    <input type="submit" value="Submit"> 

<div id='textone'></div><div id='texttwo'></div>


$arr = array( 'textone' => $_POST['mytext1'], 'texttwo' => $_POST['mytext2'] );
echo json_encode( $arr );


jQuery('#myformid').live('submit',function(event) {
        url: '_home.php',
        type: 'POST',
        data: $('#myformid').serialize(),
        success: function( data ) {
            // TODO: write code here to get json data and load DIVs instead of alert
    return false;

Output on submit:


I want to load mytext1 value in textone DIV and mytext2 value in texttwo DIV using json data in _home.php

Hint: I am using this answer to do the same task on link click event. But how to do this on form submission ?


Read more here: Source link