jQuery JSON解析问题

Zip*_*ppy 1 javascript jquery jsonp

需要一些建议我在客户端JSON解析期间做错了什么...提示和评论欢迎我的代码什么都不返回.调试器也没有显示任何有用的东西.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){                   
        var htmlString = "test";
    $.getJSON("http://search.twitter.com/search.json?callback=functionName&q=%23csharp", functionName);

    function functionName(data) {

            $.each(data.items, function(i,item){
            htmlString += item.content + "<br>";
            });
            $('#test').html(htmlString);
        }

    });
</script>

</head>
<body>
<div id="test"></div>
Run Code Online (Sandbox Code Playgroud)

lon*_*day 6

不要指定回调函数的名称.jQuery会为你做这件事.处理JSONP请求的函数是专门构造的,允许您正常使用函数并提供其他有用的功能.

这样做callback=?,而不是:

$.getJSON("http://search.twitter.com/search.json?callback=?&q=%23csharp", functionName);
Run Code Online (Sandbox Code Playgroud)

另一个问题是:

$.each(data.items, function(i,item){
Run Code Online (Sandbox Code Playgroud)

你正在迭代data.items.这在响应中不存在.然后你要求item.content.这也不存在.我不知道你正在为你的代码设计什么JSON,因为它不是JSON twitter发送的.