Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent SuperAgent AJAX from calling OPTIONS?

I found the source of my problem for SuperAgent (http://visionmedia.github.com/superagent/) on Firefox. Not sure if SuperAgent is doing it in its AJAX call or if FireFox is triggering it.

Essentially, every time I make an AJAX call an OPTIONS method is being fired on the URL before the actual AJAX call. Quite annoying since the server currently doesn't support OPTIONS. How can I make a call without it going to crap and re-coding the server?

Thanks

like image 492
crockpotveggies Avatar asked Jun 29 '12 04:06

crockpotveggies


People also ask

What is SuperAgent used for?

SuperAgent is a small HTTP request library that may be used to make AJAX requests in Node. js and browsers.

What are options requests?

Options request is a preflight request when you send (post) any data to another domain. It's a browser security issue.

What is SuperAgent in Nodejs?

SuperAgent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs. It also works with Node. js!


1 Answers

Ok found out some more details. Thankfully testing on Safari gave me more insight into what was actually happening and I applied my knowledge here.

It seems to be the standard that browsers are calling an OPTIONS method before making an actual AJAX call. Seems a bit overbearing.

So to get around it I simply added a catch-all in my reverse proxy server to handle each OPTIONS call. You can see the question below for the code:

Play! 2.0 easy fix to OPTIONS response for router catch-all?

And if you want to read up more on why browsers are doing this, see here:

Why am I getting an OPTIONS request instead of a GET request?

OPTIONS is from the CORS standard.

like image 166
crockpotveggies Avatar answered Oct 12 '22 07:10

crockpotveggies