Authored by 郝肖肖

逛详情页收藏APP跨域问题

... ... @@ -43,6 +43,12 @@ const praiseArticle = (req, res, next) => {
* 资讯文章收藏 (APP里显示收藏)
*/
const collectArticle = (req, res, next) => {
let allowOrigin = _.get(req, 'headers.origin', null) ?
req.headers.origin : req.protocol + '://' + req.headers.host;
res.setHeader('Access-Control-Allow-Origin', allowOrigin);
res.setHeader('Access-Control-Allow-Credentials', 'true');
let result = {
code: 400,
message: '您未登录,无法收藏或者取消收藏。请先登录!',
... ...
... ... @@ -164,13 +164,16 @@ function initInfosEvt($container) {
$.ajax({
type: 'POST',
url: '/guang/opt/collectArticle',
url: location.protocol + '//m.yohobuy.com/guang/opt/collectArticle',
data: {
id: $info.data('id'),
opt: opt,
yh_channel: yhChannel,
uid: uid
},
xhrFields: {
withCredentials: true
},
success: function(data) {
if (data.code && data.code === 200) {
... ...
... ... @@ -157,6 +157,9 @@ function initInfosEvt($container) {
yh_channel: yhChannel,
uid: getUrlParam('uid')
},
xhrFields: {
withCredentials: true
},
success: function(data) {
if (data.code && data.code === 200) {
// 切换收藏状态
... ...