is the syntax of the jquery correct?
the first two lines in the code of jquery
$("input[name='title']").val(json.title);
$("input[name='age']").val(json.age);
is two insert data in the forms
the next line is to display all the echoed elements in the server:
$('#age').html(json).show();//at age part of the html
the first two lines inserting elements in the form works fine,but displaying the echo elements does not work fine..is there anything wrong in the code??
Code:
$(document).ready(function(){
$("#button1").click(function(){
$.post(
'script.php',
{ id: $('input[name="id"]', '#myForm').val() },
function(json) {
$("input[name='title']").val(json.title);
$("input[name='age']").val(json.age);
$('#age').html(json).show();
},
"json"
);
});
});
<div id="age"></div>
Your problem is in this line:
The
html()function is expectiong a string. You’re passing it the JSON object that you got back.