Reputation: 1
I cannot get this $.ajax function to work in Chrome. When I make the ajax request, a response is never returned. When I view this in Chrome dev tools, it states that the json request is still pending. So far, I have found suggestions to add these parameters to the options.
'{type: "post", data: '', cache: false, async: false}'
However, none of these options made it work.
try {
var o = {username: 'adobeedge', count: 4};
var twitterUrl = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' + o.username + '&count=' + o.count;
$("body").append('<p>attempting ajax</p>');
$.ajax({url: twitterUrl,
dataType: 'jsonp',
type: "post",
data: '',
cache: false,
async: false,
})
.success(function(data) {
$.each(data, function(index, item) {
$("body").append(item.text);
});
}) ;
}
catch (error) {
alert("Error: " + error.toString());
}
Upvotes: 0
Views: 3591
Reputation: 1307
I battled with this issue today on a fully patched Chrome on OSX 10.8.2, with the exact symptoms you describe. This was the only mention of my problem I could find through Google.
Turns out it was being caused by a privacy-focused extension called Disconnect.
Try disabling extensions to see if that fixes the issue. Hope this helps.
Upvotes: 0
Reputation: 396
Following code works fine in my case
My chrome Version : 23.0.1271.95 m
try {
var o = {username: 'adobeedge', count: 4};
var twitterUrl = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' + o.username + '&count=' + o.count;
$("body").append('<p>attempting ajax</p>');
$.ajax({url: twitterUrl,
dataType: 'jsonp',
type: "post",
data: '',
cache: false,
async: false,
})
.success(function(data) {
$.each(data, function(index, item) {
$("body").append(item.text);
});
}) ;
}
catch (error) {
alert("Error: " + error.toString());
}
Upvotes: 1
Reputation: 997
jsonp
does not support synchronous calls. Try async: true
.
I'm not able to try it as I work in an office where twitter is blocked.
Upvotes: 0
Reputation: 12508
I don't know if this will be of any help, but I've never seen the success function attached on the outside of the ajax call. All the jQuery ajax documentation I've looked at shows the ".done" attached to the end. However, I've only seen success defined as an option inside the actual ajax call itself. You could try rewriting it as follows:
$.ajax({
url: twitterUrl,
dataType: 'jsonp',
type: "post",
data: '',
cache: false,
async: false,
success: function(data) {
$.each(data, function(index, item) {
$("body").append(item.text);
});
}
});
See if this helps. There is also another Stack Overflow Article that may be of some help to you as well. This article describes the different uses of "success:" vs. ".done". For more information on the .ajax documentation visit the jQuery API documentation for .ajax.
Hope this helps.
Upvotes: 0