Convert jquery code to prototype for cross browser Ajax request to get latest tweets

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"

. .

+5
3

, Dandean JSONP js.

( ), Ajax.JSONRequest Dandean ( , ). , , , , , jquery. , , Ajax.JSONRequest. . , URL- params.

, URL-

GET (twitter.com/status/user_timeline/apocalyptic_AB.json?count=1&&callback=?&callba‌ck=_prototypeJSONPCallback_0) 

, URL . , :

Resource interpreted as Script but transferred with MIME type application/json

:

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);
    });
+2

.

0

Regarding the error [Refused to get an unsafe “X-JSON” header], this can happen if your page is under SSL, but the URL provided in your AJAX call is also not an HTTPS URL.

0
source

All Articles