我已经实现了一个向我的服务器发送请求的 Openlayers BBOX 策略。它的参数在 URL 中。我通过 CakaPHP 回复一个 jsonp 对象。
出于某种原因,一些请求结束了会话,我没有得到一个 jsonp 返回,而是一个重定向到登录页面的页面。在 Firebug 的“NET”选项卡中,您可以看到登录页面的 HTML。
这是 URL(出错的请求):
http://localhost/tests/poi?bbox=4.151161804326345,51.66178773716078,5.615090026982677,52.04772606902698&callback=OpenLayers.Protocol.Script.registry.c2
萤火虫:
GET poi?bbox=4.1511618...Script.registry.c2, 302 Found, localhost, 0KB, 127.0.0.1:80
尽管响应显示为 0KB,但响应的 HTML 视图显示了登录页面。您在 Firebug 中看到的实际错误也是:
SyntaxError: syntax error <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//E
请求标头:
GET /tests/poi?bbox=4.151161804326345,51.66178773716078,5.615090026982677,52.04772606902698&callback=OpenLayers.Protocol.Script.registry.c2 HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: */*
Accept-Language: nl,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Referer: http://localhost/tests/newmap
Cookie: __utma=111872281.1525876557.1329838516.1338476641.1338488176.228; __utmz=111872281.1329838516.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _pk_id.1.1fff=00b25fc2e71f2d76.1349166387.64.1350986193.1350979575.; _pk_cvar.1.1fff=%7B%221%22%3A%5B%22User%22%2C%22Jeroen%20Bosch%22%5D%2C%222%22%3A%5B%22Relation%22%2C%22Thunderbuild%20BV%22%5D%7D; _pk_ses.1.1fff=*
响应标头:
HTTP/1.1 302 Found
Date: Tue, 23 Oct 2012 09:56:37 GMT
Server: Apache/2.2.21 (Win64) PHP/5.3.8
X-Powered-By: PHP/5.3.8
Set-Cookie: CAKEPHP=q16jb0grsk4rv3krb3rc40cj22; expires=Tue, 23-Oct-2012 13:56:37 GMT; path=/
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Location: http://localhost/users/login
Content-Length: 0
Keep-Alive: timeout=5, max=73
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
服务器上的代码:
public function poi() {
$this->layout = false;
if (!isset($this->request->query['bbox'])){
$this->log($this->request, 'debug');
return;
}
$bounds = $this->request->query['bbox'];
$callback = $this->request->query['callback'];
$data = $this->Location->getBoundedLocations($bounds);
$this->set('callback', $callback);
$this->set('json', $data);
$this->render('../Elements/jsonp');
}
jsonp 元素只是一个普通的 json_encode 并且也将它包装在回调函数中。我不明白为什么有时(实际上经常)这会结束会话。我不知道如何解决这个问题。
非常感谢您的想法!