views:

123

answers:

4

in the $.ajax function the url part has data.json which is a text file but i want to put a url i.e.

the code works with

$(document).ready(function() {

    $('#content').html('');
    $.ajax({
            url:'data.json',
            dataType: "json",
            success: function(data) {
                    $('#content').append('<p>'+data.rank+'</p>');
            }
    });});

where data.json is a text file...but wen i replace 'data.json' with 'http://twittercounter.com/api/username=Anand_Dasgupta&amp;output=json&amp;results=3'...which is the actual url ,then there is no output...

$(document).ready(function() {

    $('#content').html('');
    $.ajax({
          url:'http://twittercounter.com/api/username=Anand_Dasgupta&amp;output=json&amp;results=3',
            dataType: "json",
            success: function(data) {
                    $('#content').append('<p>'+data.rank+'</p>');
            }
    });});

an advice will be highly appreciated. Thank You.

+1  A: 

Seems you have typo in url, the question mark is significant since it differentiate url from parameters:

http://twittercounter.com/api/?username=Anand_Dasgupta&amp;output=json&amp;results=3

As for me looks like missing some more parameters.

EDIT:

The below answers looks more correct than mine, it definitely could be cross domain access.

Artem Barger
+5  A: 

This seems to be a case of cross domain ajax prevention.

You will need to use a server side proxy script for this.

Here Be Wolves
+1  A: 

As @harshath.jr correctly pointed out, you will need to proxy that request through your domain, for example:

  $('#content').html('');
    $.ajax({
          url:'twitterProxy.php?username=Anand_Dasgupta&results=3',
            dataType: "json",
            success: function(data) {
                    $('#content').append('<p>'+data.rank+'</p>');
            }
    });});
karim79
kim3er
@kim3er - absolutely, I threw in the above example to better illustrate what it means to proxy the request, I will edit the answer to reflect the better-practice you have suggested.
karim79
anand
+1  A: 

using $.getJSON should solve all your worries. And it'll call you in the morning.

Oli