Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
81
rated 0 times [  83] [ 2]  / answers: 1 / hits: 24568  / 12 Years ago, wed, march 28, 2012, 12:00:00

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


More From » jquery

 Answers
9

If I understand correctly with the object up top being the JSON response, I think you want this...



{id:,livre:empty_name}

$.ajax({
url: sent.php,
type: post,
dataType: json,
data: formdata,
success: function (data) {
var jsonId = data.id;
}
});


The data parameter of the success callback contains your response (in this case, JSON data). You access your JSON content there.


[#86556] Tuesday, March 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kevenjeffreyr

Total Points: 286
Total Questions: 112
Total Answers: 95

Location: Zambia
Member since Thu, Jun 25, 2020
4 Years ago
;