Last Updated: July 19, 2020
·
1.342K
· gianttoast

Enabling cross domain requests in jQuery

jQuery 1.5 and up does not support cross domain requests by default (for good reason). This can be problematic when you are trying to test something that has to make ajax calls to external web services. So if you are wondering why your $.ajax calls keep failing, try adding this little snippet to the top of your javascript file:

jQuery.support.cors = true;

Hope that helps someone, it caused me quite the headache the other day.

1 Response
Add your response

you can also set crossDomain property to true

over 1 year ago ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside