简体   繁体   中英

Cross-domain AJAX calls during development: possible?

I am developing applications using Angular and the client side is 100% JS. I am about to replace an old application made using ExtJS but I will not change the server-side. Only the client-side be re-coded from scratch.

I would like to work on this project from anywhere and any machine but I need to be able to perform cross-domain AJAX queries with the original server (server-side is ASP.NET MVC with IIS and I don't want to install Windows + everything on all the computers I use). Is there a way to do this easily?

Thanks for your ideas!

PS: JsonP is not a solution for me.

Couple of things:

  1. At the end of the day you have to enable CORS in your server.
  2. You can use a CORS proxy https://github.com/gr2m/CORS-Proxy for development. This proxy will actually change the request header of X-Origin which browsers even can but "won't" because of policy. So you will be able to make Cross Origin Requests.

If neither JSONP nor CORS are availble to you as options then you will have to take help of server side scripting.

You can create a method in your server side code and get the response from desired cross domain url and return the response to your javascript function.

您可以使用CORS (跨源资源共享)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM