1

So I'm totally new to this, but jsonp seemed so simple, I'm just trying to make a web app using dashcode. I need to put twitter json data on a page of my web app. This is what I tried.

I put this code in index.html

<script src="http://twitter.com/users/USERNAME.json?callback=handleResponse"/>

Then I created a javascript file

function handleResponse(responseJson){
alert(responseJson.status.text);
}

When I put the javascript file as the datasource I get an error saying it is not valid JSON or XML. As I said I am new to this, so I might be doing it completely wrong.

citizen conn
  • 15,300
  • 3
  • 58
  • 80
Davis Gossage
  • 39
  • 1
  • 4

3 Answers3

0

You code works, at least in Chrome, with one small tweak - see http://jsfiddle.net/nrabinowitz/jJTQn/1/

<script type="text/javascript">
function handleResponse(responseJson){
    alert(responseJson.status.text);
}
</script>
<script type="text/javascript"
 src="http://twitter.com/users/Pogue.json?callback=handleResponse"></script>

The small tweak is closing the script tag properly (script tags can't be self-closing, for reasons I'm apparently too lazy to Google). Wouldn't hurt to throw type="text/javascript" in there too.

nrabinowitz
  • 55,314
  • 10
  • 149
  • 165
0

You need to make sure the handleResponse function is defined before the external jsonp call.

(Also your script tag is invalid)

<script>
function handleResponse(responseJson){
  alert(responseJson.status.text);
}
</script>
<script src="http://twitter.com/users/USERNAME.json?callback=handleResponse"></script>
Ben Rowe
  • 28,406
  • 6
  • 55
  • 75
0

Click on “Widget Attributes” in the left-hand source pane. Under “Network / Disk Access”, make sure that “Allow Network Access” is checked. Without this checked your widget won’t be able to make any AJAX requests.

bdesham
  • 15,430
  • 13
  • 79
  • 123