I has been issue when I call ajax from sencha to grails.
XMLHttpRequest cannot load http://localhost:8080/ExtLogin/userInfo/index/login. Origin http://localhost:9090 is not allowed by Access-Control-Allow-Origin.
Code below:
Sencha: Sencha application deploying on “http://localhost:9090/sencha/demo/Login/” using Tomcat
Grails application using Tomcat at “http://localhost:8080/ExtLogin/userInfo/index/login”. Login function at server side render JSON is below:
def login(){
def response = ['success':'true']
response.addHeader("Access-Control-Allow-Origin", "*")
response.addHeader("Cache-Control", "no-cache")
render response as JSON
}
If request from browser, I received:
Request URL: http://localhost:8080/ExtLogin/userInfo/login
Request Method: GET
Status Code: 200 OK
Request Headersview source
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset: UTF-8,*;q=0.5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:8080
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.160 Safari/537.22
Response Headers: Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Type:application/json;charset=UTF-8
Date: Mon, 11 Mar 2013 02:33:35 GMT
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
==
And if request from sencha app, I received:
Request URL:http://localhost:8080/ExtLogin/userInfo/index/login
Request Method: OPTIONS
Status Code: 200 OK
Request Headersview: Accept: */*
Accept-Charset: UTF-8,*;q=0.5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Access-Control-Request-Headers:origin, x-requested-with, content-type
Access-Control-Request-Method: POST
Connection: keep-alive
Host: localhost:8080
Origin: http://localhost:9090
Referer: http://localhost:9090/sencha/demo/Login/
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.160 Safari/537.22
Response Headers Allow:
GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS
Content-Length: 0
Date: Mon, 11 Mar 2013 02:44:03 GMT
Server: Apache-Coyote/1.1
Please help me!