Powered by Blogger.

JQUERY AJAX XMLHTTPREQUEST CANNOT LOAD URL


Url is not allowed by Access-Control-Allow-Origin due to Cross-Origin Resource Sharing (CORS)- ERROR
XMLHttpRequest cannot load http://myApiUrl/login. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access.
Corsa proxies HTTP requests, add CORS headers, and can also serve your static web application.
Features:
  • proxy requests for /proxy/http://host/path to http://host/path
  • set Access-Control-Allow-Origin headers
  • support for CORS preflight requests
  • support for GET, HEAD, POST, PUT, DELETE, OPTIONS
  • serve static content from /app/ (--app-dir)
  • limit proxy hosts (--allow-proxy)
  • limit origin (--allow-origin)

INSTALLATION

Corsa is written in Python
$ apt-get install python-pip
$ pip install corsa
To permit all origins and proxy hosts with the ALL alias:
Open the directory where your application is, then execute the command in terminal
 $ corsa --allow-proxy ALL --allow-origin ALL
It would give you a response as follows
Starting Corsa…
CORS proxy at http://localhost:8888/proxy/
Now change the url in the jquery ajax-call like
Then finally browse with URL “localhost/yourapplication”

No comments