$('#button').click(function(){
$.ajax({
url : "test2.php",
data : $("#tab"),
type : "GET",
success : function(b){
b = eval('('+ b +')');
console.log((b['t']));
alert(b);
}
});
});
Asked
Active
Viewed 1,546 times
-3

Pranav C Balan
- 113,687
- 23
- 165
- 188

Ritu
- 23
- 6
-
http://api.jquery.com/jquery.get/ – Kostas Mitsarakis Nov 21 '15 at 12:17
-
you can use JSON.parse - almost same question here. http://stackoverflow.com/questions/9991805/javascript-how-to-parse-json-array – Ray Nov 21 '15 at 12:18
4 Answers
0
You shouldn't use eval(). You can either set the data type on the request as JSON or use JSON.parse();
$('#button').click(function(){
$.ajax({
url : "test2.php",
data : $("#tab"),
type : "GET",
success : function(b){
b = JSON.parse(b);
console.log((b['t']));
alert(b);
}
});
});
//datatype as JSON
$('#button').click(function(){
$.ajax({
url : "test2.php",
data : $("#tab"),
type : "GET",
dataType: "json",
success : function(b){
console.log((b['t']));
alert(b);
}
});
});

kurt
- 1,146
- 1
- 8
- 18
0
You can get data using "parseJSON"
$('#button').click(function(){
$.ajax({
url : "test2.php",
data : $("#tab"),
type : "GET",
success : function(b){
var obj = jQuery.parseJSON(b);
console.log(obj);
}
});
});

Jalpa
- 697
- 3
- 13
0
Since you are using Jquery, try this:
$('#button').click(function(){
$.ajax({
url : "test2.php",
data : $("#tab"),
type : "GET",
success : function(b){
var obj=jQuery.parseJSON(b);
alert(obj.<name>);
}
});
});

Manikiran
- 2,618
- 1
- 23
- 39
-
-
-
Could you provide some values of your json? Btw in the following code, `obj.
` change ` – Manikiran Nov 21 '15 at 12:49` to your key.
0
Since you are using AJAX, you can directly set the dataType as json and no need to again parse the data.
$('#button').click(function(){
$.ajax({
url : "test2.php",
data : $("#tab"),
dataType : "json",
type : "GET",
success : function(b){
// b is in the JSON format, print the complete JSON
console.log(JSON.stringify(b));
console.log(b['t']);
alert(b);
}
});
});

Chandan
- 1,128
- 9
- 11