I have this code that works well:
{"livre":"empty_name"}
$.ajax({
url: "sent.php",
type: "post",
dataType: "json",
data: formdata,
success: function (data) {
switch (data.livre) {
case 'empty_name':
break;
}
});
but when i try this code (i need the id), the case “empty name” didn’t works. The option selected will be the default case:
{"id":"","livre":"empty_name"}
$.ajax({
url: "sent.php",
type: "post",
dataType: "json",
data: formdata,
success: function (id, data) {
switch (data.livre) {
case 'empty_name':
break;
}
});
Why? and how can be solved? thanks
If I understand correctly with the object up top being the JSON response, I think you want this…
The
dataparameter of thesuccesscallback contains your response (in this case, JSON data). You access your JSON content there.