1
Ajax GET
Angular调用失败。使用机器IP访问本地主机会导致Ajax调用失败
它提出了以下错误:
XMLHttpRequest cannot load http://localhost:3000/learning_record_service/get_document?document_id=288. Origin http://127.0.0.1:3000 is not allowed by Access-Control-Allow-Origin.
这里是请求的详细信息:
Request URL:http://localhost:3000/learning_record_service/get_document?document_id=288
Request Method:OPTIONS
Status Code:200 OK
Request Headersview source
Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, origin, x-requested-with
Access-Control-Request-Method:GET
Connection:keep-alive
Host:localhost:3000
Origin:http://127.0.0.1:3000
Referer:http://127.0.0.1:3000/documents/open/288?sc=c961d72844bbc5439923e097860057d0&angular=1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.22 (
虽然这里是代码:
$http.get('/learning_record_service/get_document?document_id=' + document_id).success(function(data){
//success code
});
您正在使用哪种浏览器?我记得用Chrome我有这个问题,如果我没有错,它与Firefox的工作。无论如何,我使用一些像Appfog这样的管理域来执行这种请求。 – steo 2013-03-17 19:21:02
你必须要求一个相同的主机+端口(也是方案,例如http或https)。 – Gael 2013-03-17 19:21:29
为什么它在相同的请求中显示127.0.0.1和localhost。是他们中的任何一个硬编码? – Anoop 2013-03-17 19:24:59