is this syntax correct in jquery
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)开发者_C百科.show();
},
"json"
);
});
});
<div id="age"></div>
Your problem is in this line:
$('#age').html(json).show();
The html()
function is expectiong a string. You're passing it the JSON object that you got back.
$(document).ready(function(){
is missing its closing brackets. Add });
at the end of your javascript.
$(document).ready(function(){
});
精彩评论