サーバーにリクエストを送信するOpenlayersBBOX戦略を実装しました。引数はURLにあります。Jsonpオブジェクトを使用してCakaPHP経由で返信します。
何らかの理由でいくつかのリクエストがセッションを終了し、jsonp returendが表示されませんが、ログインページへのリダイレクトであるページが表示されます。Firebugの[NET]タブで、ログインページのHTMLを確認できます。
(失敗したリクエストの)URLは次のとおりです。
http://localhost/tests/poi?bbox=4.151161804326345,51.66178773716078,5.615090026982677,52.04772606902698&callback=OpenLayers.Protocol.Script.registry.c2
Firebug:
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であり、コールバック関数でラップします。なぜ時々(実際にはかなり頻繁に)これがセッションを終了するのか理解できません。これを修正する方法がわかりません。
あなたの考えに感謝します!