I've got the following code :
$.post("docsel.php", {id : id}, function(data) {
$('input#titre').val(data.titre);
$('input#content').val(data.content);
});
docsel.php returns a JSON encoded array with titre and content and their values.
I checked that returned data is correct.
Now I'd like to modify input fields with results, but my code doesn't work. What am I doing wrong?
EDIT:
Here is the data (i put auteur and not content to simplify) :
"[{"titre":"Dipt\u00e9rosodomanie et t\u00e9trapilotomie radiaire, pourquoi ?","auteur":"Alex"}]"
I modified my code like this :
$.post("docsel.php", {id : id}, showResult(data));
});
});
function showResult(data)
{
var obj = JSON.parse(data);
var titre = obj.titre[0];
$('#titre').val(titre);
but it doesn't work, I mean input field "titre" is not modified. Please take into account that I am an absolute beginner in JQuery / Php .
idis always unique:$('#titre'). Or are you saying it isn't unique?