I'm using Jquery and ajax.
I have a simple form and my jquery :
This is a piece of the code :
username = $('input[name="username"]').val(); $.post("api.php", {username: username}, function(data) { if(data == "error") { data("erreur"); } else { alert(data); $('input[name="subscribers"]').attr("placeholder", "something").blur(); $('input[name="viewCount"]').attr("placeholder", "something").blur(); } }); And the result of alert(data);
{"total":"628729","abo":"1646"} I would like to put the result of total and the result of abo into my placeolder :
$('input[name="subscribers"]').attr("placeholder", ?abo?).blur(); But i don't know who to recover the result of the json and take the value of total and abo
note : my json is genrate by the file api.php with json_encode
$.postcall:$.post('api.php', {username: username}, function(data){}, 'json'), to tell jQuery to parse the JSON. Thendata` will be an object (not a function). Then you can accessdata.totalanddata.abo."error". Reply with{error:true}, so that you can have jQuery parse it as JSON and check fordata.errorJSON.parse, but it's up to you.