Modify JSONP Header

1,050 views
Skip to first unread message

Sid-ahmed D

unread,
Dec 19, 2012, 9:37:02 PM12/19/12
to mootool...@googlegroups.com
Hello Everybody,

Could you please say me if we can modify Header in JSONP request ?
I use Mootools framework to make JSONP requests.

Thank you.
Best regards,

Sid-ahmed D

unread,
Dec 19, 2012, 9:57:32 PM12/19/12
to mootool...@googlegroups.com
I try to connect my website with Google API Calendar (with Javascript) and i need to inject header in JSONP requests.

    var ressource = {
        "defaultReminders":[{"method":"sms", "minutes": 10}],
        "id": "CalendarTEST"
        };
       
    new Request.JSONP({
        url: 'https://www.googleapis.com/calendar/v3/users/me/calendarList',
        data : ressource,
        headers:{'Authentification': token},
        onComplete: function (json) {
             console.log(json);
         }
    }).send();
 
I would insert new calendar.

Thank you for your futur replies :)
 

Sanford Whiteman

unread,
Dec 19, 2012, 10:08:17 PM12/19/12
to Sid-ahmed D
> Could you please say me if we can modify Header in JSONP request ?
> I use Mootools framework to make JSONP requests.

You can't modify headers in JSONP. Only with full CORS support can you
get XHR-type customizability across domains.

-- Sandy

Sid-ahmed D

unread,
Dec 20, 2012, 3:18:45 PM12/20/12
to mootool...@googlegroups.com
Thank you :D

Sid-ahmed D

unread,
Dec 21, 2012, 12:50:07 PM12/21/12
to mootool...@googlegroups.com
Hello,

Is it possible to limite simultaneous requests whit XHR ?
I want to run 5 queries (for example) one by one after the end of the execution of the first.


Best regards,

Oskar Krawczyk

unread,
Dec 21, 2012, 12:56:23 PM12/21/12
to mootool...@googlegroups.com
Request.Queue

Sid-ahmed D

unread,
Dec 21, 2012, 1:10:51 PM12/21/12
to mootool...@googlegroups.com
Could you please confirmed me if this example can work, because i tested and it's not working ...?

insert_events(id, json[1]);
insert_events(id, json[2]);
insert_events(id, json[3]);
insert_events(id, json[4]);
insert_events(id, json[5]);
insert_events(id, json[6]);
insert_events(id, json[7]);
insert_events(id, json[8]);

var insert_events = function insert_events(id, ressource){
    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'https://www.googleapis.com/calendar/v3/calendars/'+id+'/events');
    xhr.setRequestHeader('Authorization', 'Bearer ' + CookieToken);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.send(JSON.encode(ressource));
}

var myQueue = new Request.Queue({
    requests: insert_events,
    onComplete: function(name, instance, text, xml){
        console.log('queue: ' + name + ' response: ', text, xml);
    }
});

magic77

unread,
Dec 25, 2012, 3:27:35 PM12/25/12
to mootool...@googlegroups.com
hi,
maybe this one is helpful: https://github.com/visionmedia/superagent



--
View this message in context: http://mootools-users.660466.n2.nabble.com/Moo-Modify-JSONP-Header-tp7580893p7580904.html
Sent from the MooTools Users mailing list archive at Nabble.com.

Sanford Whiteman

unread,
Dec 25, 2012, 4:09:43 PM12/25/12
to magic77
> maybe this one is helpful: https://github.com/visionmedia/superagent

There's no Ajax framework that can work around these limitations.

Frameworks cannot circumvent native browser security, only simplify
access. So if you're not wrapping CORS, you do not solve the prob.

-- S.

Sid-ahmed D

unread,
Dec 25, 2012, 4:22:36 PM12/25/12
to mootool...@googlegroups.com
Thank you for all reply guys :D

magic77

unread,
Dec 25, 2012, 4:24:13 PM12/25/12
to mootool...@googlegroups.com
Hi Sanford,
one framework exists - it uses Flash as Proxy - i´ve used this once and it
worked.
https://github.com/flensed/flXHR

greets



--
View this message in context: http://mootools-users.660466.n2.nabble.com/Moo-Modify-JSONP-Header-tp7580893p7580907.html

Sanford Whiteman

unread,
Dec 25, 2012, 4:39:48 PM12/25/12
to mootool...@googlegroups.com
Flash as proxy is beyond XHR. You might add in Silverlight and Java bridges, too!

The obvs. point is that you can't use JSONP as it is commonly understood (script injection) w/custom headers, nor is there a modern-browser-native XHR/XDR/XHR2 solution that will work (largely because of MS' architectural decisions w/XDR).

The "rightest" way to do this now is by passing auth tokens in the URL; JSONP calls don't appear in the URL bar, anyway.

-- S.

magic77

unread,
Dec 25, 2012, 4:46:43 PM12/25/12
to mootool...@googlegroups.com
sure you´re right :-)

If you reply to this email, your message will be added to the discussion below:
http://mootools-users.660466.n2.nabble.com/Moo-Modify-JSONP-Header-tp7580893p7580908.html
To unsubscribe from [Moo] Modify JSONP Header, click here.
NAML



View this message in context: Re: [Moo] Modify JSONP Header

Sanford Whiteman

unread,
Dec 25, 2012, 5:20:36 PM12/25/12
to mootool...@googlegroups.com
I still use applets myself that implicitly circumvent SOP, I just don't want to be quoted recommending that approach anymore. :P

Especially with iOS in mind -- if you can't build in server-side CORS awareness (like on shared hosting), you have to build for JSONP w/authorization anyway, so might as well embrace it everywhere instead of leaning on Flash.

True that if a given 3rd-party web service is known to support CORS and not JSONP w/auth, Flash bridge is worthy for IE in that case.

-- S.

Reply all
Reply to author
Forward
0 new messages