The current situation is:
The session_id generated by directly accessing cd.xxx.com is the same as the session_id generated by accessing www.xxx.com
But using ajax in cd.xxx.com to request www.xxx.com will generate a new one session_id causes verification failure!
Is there any way to deal with it? Thanks in advance!
The current situation is:
The session_id generated by directly accessing cd.xxx.com is the same as the session_id generated by accessing www.xxx.com
But using ajax in cd.xxx.com to request www.xxx.com will generate a new one session_id causes verification failure!
Is there any way to deal with it? Thanks in advance!
This problem belongs to the problem of Ajax carrying cookies across domains. I found a solution in a blog post.
Native ajax request method:
<code>var xhr = new XMLHttpRequest(); xhr.open("POST", "http://xxxx.com/demo/b/index.php", true); xhr.withCredentials = true; //支持跨域发送cookies xhr.send();</code>
jquery post method request:
<code> $.ajax({ type: "POST", url: "http://xxx.com/api/test", dataType: 'jsonp', xhrFields: {withCredentials: true}, crossDomain: true, })</code>
Server side settings:
<code>header("Access-Control-Allow-Credentials: true"); header("Access-Control-Allow-Origin: http://www.xxx.com");</code>
Thanks to the original author:
http://blog.sina.com.cn/s/blo...