javascript - cross domain ajax POST fails with CORS and Tomcat -
i have been banging head against wall while trying cross domain ajax calls work.
i have enabled cors on tomcat 7.0.5.0 server (windows), , can requests javascript, post requests still fail access denied. before enabling cors failed, seems working bit.
the same code works fine same host, fails on remote hosts.
i have tried everything, , every browser, no luck.
javascript code:
var request = new xmlhttprequest(); var debug = this.debug; request.onreadystatechange = function() { console.log(request.statustext); console.log(request.responsetext); console.log(request.responsexml); if (request.readystate != 4) return; if (request.status != 200 && request.status != 204) { console.log('error: sdk post web request failed'); } ... }; request.open('post', url, true); request.setrequestheader("content-type", "application/xml"); request.send(xml);
tomcat web.xml
<filter-name>corsfilter</filter-name> <filter-class>org.apache.catalina.filters.corsfilter</filter-class> </filter> <filter-mapping> <filter-name>corsfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
i tried adding,
<init-param> <param-name>cors.allowed.headers</param-name> <param-value>content-type,x-requested-with,accept,origin,access-control-request-method,access-control-request-headers,authorization</param-value> </init-param>
and even,
<filter> <filter-name>webdavfixfilter</filter-name> <filter-class>org.apache.catalina.filters.webdavfixfilter</filter-class> </filter>
but no luck. please help.
okay, working now. seems bug in code. using wrong url...
Comments
Post a Comment