$('#button').click(function(){
$.ajax({
url : "test2.php",
data : $("#tab"),
type : "GET",
success : function(b){
b = eval('('+ b +')');
console.log((b['t']));
alert(b);
}
});
});
-3
A
回答
0
您不應該使用eval()。您可以將請求上的數據類型設置爲JSON或使用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);
}
});
});
+0
我們怎樣才能 – Ritu
0
由於您使用jQuery你可以使用 「parseJSON」
$('#button').click(function(){
$.ajax({
url : "test2.php",
data : $("#tab"),
type : "GET",
success : function(b){
var obj = jQuery.parseJSON(b);
console.log(obj);
}
});
});
0
0
由於您使用AJAX,你可以直接將dataType設置爲json,而不需要再次解析數據。
$('#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);
}
});
});
相關問題
- 1. 如何獲得數組中的json值
- 2. 如何獲得JSON數組值到J2ME
- 3. 如何在Ajax獲得此JSON數據
- 4. 如何獲得json數組
- 5. 如何獲得下拉選擇在json數組中的值
- 6. 如何獲得JSON數組內的JSON數組中的Android
- 7. 如何獲得json數組的總數?
- 8. 如何從json數組中獲得特定值?
- 9. JSON - 如何獲得數組中的特定值?
- 10. 如何從數組中獲得值
- 11. 如何從數組中獲得值
- 12. 如何獲得維數組中的值?
- 13. 如何從數組中獲得值
- 14. 如何從數組中獲得價值?
- 15. 如何獲得JSON數組的最大
- 16. 如何獲得JSON數組out對象
- 17. 獲得從嵌套數組(JSON)值
- 18. 不能從Json數組獲得鍵值:
- 19. 如何獲得JSON值?
- 20. 如何通過JSON數組獲得價值如查詢
- 21. 如何獲得json的值,如果它返回結果數組?
- 22. jquery ajax獲取json數組?
- 23. 如何在Ajax調用中獲得兩個數組?
- 24. 如何獲取Json對象數組值?
- 25. 如何獲得json編碼數組在JavaScript中的長度?
- 26. 如何獲得json數據在跨域使用ajax
- 27. 從JSON數組中獲得「分數」
- 28. 在json中的關聯數組中循環jquery並獲得數組值
- 29. json如何發送數組在AJAX
- 30. 如何在C#中獲取Json數組?
b是一個json數組? – Ray
http://api.jquery.com/jquery.get/ –
你可以使用JSON.parse - 這裏的問題幾乎相同。 http://stackoverflow.com/questions/9991805/javascript-how-to-parse-json-array – Ray