Reputation: 1023
I have a function to get JSON data from another domain, but I don't know what is wrong with it. It never fires the success function and and no errors are returned.
$.ajax({
url: "http://other-domain.com/sample/Json.aspx",
dataType: "jsonp",
type: 'get',
crossDomain: true,
jsonp: 'jsonp_callback',
success: function() {
alert('abc'); //when success take json data string but i din get in here
}
});
Does anyone know what's wrong here?
Upvotes: 1
Views: 674
Reputation: 2250
Try:
$.get('http://other-domain.com/sample/Json.aspx', function(data) {
alert(data);
});
You should get an alert with a json string (which is actually a string), than use jQuery.parseJSON(data)
on it and you'll get a JSON object to work on.
If this doesn't work, maybe you need to check your get parameters.
Edit:
I just tried to set up this page right now:
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?',function(data){
alert(data.title);
});
});
</script>
</head>
<body>
... WHATEVER ...
</body>
and it works just fine, it's alerting the first title element in the data object.
Upvotes: 1