Ajax Json解析了空白结果 [英] Ajax Json parsed blank result

查看:65
本文介绍了Ajax Json解析了空白结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过AJAX解析一些JSON数据i跟随此处的示例:

I am trying to parse some JSON data through AJAX i followed an example from here:

如何使用jquery / javascript解析json数据?

关于例如,他们可以让它工作,但在我的例子中,

变成了空白。

On the example, they can get it working, but on my exmaple, the

turned blank.

我试着回复一下php,显示的JSON也没问题。想知道问题是什么。

I tried just echoing the php, the JSON displayed with no problem either. Wondering what the problem is.

<!DOCTYPE HTML>
<html>
<head>
  <link type ="text/css" rel="stylesheet" href= "css/bootstrap.css">
 <link type ="text/css" rel="stylesheet" href= "css/account.css">
</head>



 <body>
    <p id="result">fefe</p>>
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="js/bootstrap.min.js"></script>
     <script>
    $.ajax({ 
                    type: 'GET', 
                    url: 'get.php', 
                    data: { get_param: 'value' }, 
                    dataType:'json',
                    success: function (data) { 
                                        var names = data
                        $('#result').html(data);
                    }
                });
        </script>
    </body>
    </html>

What the JSON result looks like in php:

    [{"id":"1","userid":"26","title":"654","description":"654"}]


推荐答案

什么是数据的类型?
尝试在成功函数的代码中添加此行

what is the type of data? try add this line in your code on success function

success: function (data) {
    console.log(data);
}

它是一个对象数组,如果是,也许你可以尝试这个

is it an array of objects, if yes maybe you can try this

$.ajax({ 
    type: 'GET', 
    url: 'get.php', 
    data: { get_param: 'value' }, 
    dataType:'json',
    success: function (data) { 
        for(var i=0; i<data.length; i++) {
            // do your things here using data[i].description until data[i].userid
        }
    }
});

这篇关于Ajax Json解析了空白结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆