Convert jquery code to prototype for cross browser Ajax request
My first post!
I had to bring my last tweet, so I had to execute a cross-browser request. The current application uses a prototype, but I am familiar with jquery.
So, I started with jquery like:
$.ajax('http://twitter.com/status/user_timeline/apocalyptic_AB.json?count=1&callback=?', {
dataType: "jsonp",
success:function(data,text,xhqr){
$.each(data, function(i, item) {
console.log(item.text);
});
}
});
I get a warning like:
'Resource interpreted as Script but transferred with MIME type application/json.'
But I really see the last tweet. Good.
So, I decided to do the same in the prototype, and then try to eliminate the warnings, if any. But, I didn’t get anywhere even after several hours.
This is what I originally came up with in the prototype. I had a lot of changes and changes, but no one worked.
new Ajax.Request('http://twitter.com/status/user_timeline/apocalyptic_AB.json?count=1&callback=?', {
contentType: "jsonp",
onSuccess:function(transport){
console.log(transport) ;
}
});
, nil/"". Firefox, Chrome :
XMLHttpRequest cannot load http://twitter.com/status/user_timeline/apocalyptic_AB.json?count=1&callback=?. Origin http://localhost:4000 is not allowed by Access-Control-Allow-Origin.
Refused to get unsafe header "X-JSON"
. .