javascript - Converting jquery code to prototype for a cross browser Ajax request in order to obtain Latest Tweets -
converting jquery code prototype cross browser ajax request
my first post !
i had fetch latest tweet , had perform cross browser request. current app uses prototype, familiar jquery.
so, began in jquery :
$.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 warning :
'resource interpreted script transferred mime type application/json.'
but, see last tweet. fine.
so, decided same in prototype , try eliminating warnings, if any. but, got near after trying hours.
this came in prototype. had lot of changes/alterations followed none worked.
new ajax.request('http://twitter.com/status/user_timeline/apocalyptic_ab.json?count=1&callback=?', { contenttype: "jsonp", onsuccess:function(transport){ console.log(transport) ; } });
the request succeeds response text nil / " " . no error in firefox in chrome error :
xmlhttprequest cannot load http://twitter.com/status/user_timeline/apocalyptic_ab.json?count=1&callback=?. origin http://localhost:4000 not allowed access-control-allow-origin. refused unsafe header "x-json"
any shall appreciated. thank you.
thanks darin getting me onto dandean's jsonp prototype js.
although did not mention in first place(the question getting bit long), had tried using ajax.jsonrequest dandean (the link referring to). request getting failed, , didnt go further using assuming pretty straight forward getting done in prototype too, jquery. got no more answers, justifiably so, decided wrap head around using ajax.jsonrequest. request failure not due gateway timeout. because request url had params callback repeated in it.
so, request url turned out
get (twitter.com/status/user_timeline/apocalyptic_ab.json?count=1&&callback=?&callback=_prototypejsonpcallback_0)
thus, defined url without callback , performed desired. however, still warning :
resource interpreted script transferred mime type application/json
here equivalent prototype :
new ajax.jsonrequest('http://twitter.com/status/user_timeline/apocalyptic_ab.json?count=1', { onsuccess:function(response){ response.responsejson.each(function(item){ console.log(item.text); });
Comments
Post a Comment