Need some advise on what I am doing wrong during client JSON parsing… Tips and comments welcome my code returns nothing. Debugger doesn’t show anything useful either.
<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>
Don’t specify the name of your callback function. jQuery will do that for you. The function that handles the JSONP request is specially constructed to allow you to use your function as normal and to provide other useful features.
Do
callback=?instead:The other problem is with this:
You’re iterating over
data.items. This doesn’t exist in the response. You then ask foritem.content. This doesn’t exist either. I don’t know what JSON you’re designing your code for, because it’s not the JSON twitter sends.