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 to request www.xxx.com in cd.xxx.com will generate a new session_id, leading to verification failure! Is there a solution ?, Thank you! The current situation is:
The session_id generated by directly accessing cd.xxx.com is consistent with the session_id generated by accessing www.xxx.com.
However, when you use ajax to request www.xxx.com in cd.xxx.com, a new session_id will be generated, leading to verification failure!
Is there a solution ?, Thank you!
Reply content:
The current situation is:
The session_id generated by directly accessing cd.xxx.com is consistent with the session_id generated by accessing www.xxx.com.
However, when you use ajax to request www.xxx.com in cd.xxx.com, a new session_id will be generated, leading to verification failure!
Is there a solution ?, Thank you!
This problem is caused by cross-origin Cookie of Ajax. I found a solution for a blog post.
Native ajax request method:
Var xhr = new XMLHttpRequest (); xhr. open ("POST", "http://xxxx.com/demo/ B /index.php", true); xhr. withCredentials = true; // supports cross-origin sending cookiesxhr. send ();
Jquery post method request:
$.ajax({ type: "POST", url: "http://xxx.com/api/test", dataType: 'jsonp', xhrFields: {withCredentials: true}, crossDomain: true,})
Server side settings:
header("Access-Control-Allow-Credentials: true");header("Access-Control-Allow-Origin: http://www.xxx.com");
Thanks to the original author:
Http://blog.sina.com.cn/s/blo...