Ajaxの非同期GET・POSTのレスポンスで,Cookieの値をセットする事は可能
ブラウザ上から非同期通信した場合も,
通信の結果として同一ドメインのサーバから返ってくるレスポンスを受信すれば,
そのレスポンスヘッダ内に指定されている通りに,Cookieがセットされる。
つまりWebアプリでは,Ajax通信でもクッキーは発行が可能,ということ。
根拠となる参考ページ:
Can an AJAX response set a cookie? - Stack Overflow
http://stackoverflow.com/questions/33...
- Yes, you can set cookie in the AJAX request in the server-side code just as you'd do for a normal request
- リクエストを受けるサーバ側から見れば,XHRでアクセスされたのか,普通に同期的にアクセスされたのかの違いは関係ないので,ヘッダの内容や挙動も同じ
- According to the w3 spec section 4.6.3 for XMLHttpRequest a user agent should honor the Set-Cookie header. So the answer is yes. (XHRの仕様としてクッキーを受理するように定められている)
jquery - How to get a cookie from an AJAX response? - Stack Overflow
http://stackoverflow.com/questions/12...
- GETの非同期通信時に,クッキーの中身を読み取るサンプルコード
- xhr.getResponseHeader('Set-Cookie')
Get response header jquery ajax post Set-Cookie - Stack Overflow
http://stackoverflow.com/questions/12...
- POSTの非同期通信時に,クッキーの中身を読み取るサンプルコード。GETの時と基本は同じ。
発端になった質問:
ブラウザから、http://test.com/cart?id=1 としてGETしたら、id=..
http://q.hatena.ne.jp/1388029471