角GET请求的错误,但仅限于iOS的Safari浏览器 [英] Angular GET request error, but only on safari iOS

查看:1286
本文介绍了角GET请求的错误,但仅限于iOS的Safari浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用文字preSS作为后端一个网站,并angularjs作为前端。我用这个词preSS JSON API来让我的数据传输到前端。

I'm building a website using wordpress as backend, and angularjs as frontend. I'm using the wordpress json API to get my data to the front-end.

HTTPS://word$p$pss.org/plugins/json-api/

问题

我使用的角度,从字preS JSON API获取我的数据。我创建了以下服务:

I'm using angular to get my data from the wordpres json API. I have created the following service:

this.getPage = function ( slug ) {
    return $http.get('wordpress/api/get_page/?slug=' + slug)
}

我使用这项服务在我的控制器来获取当前页

I use this service in my controller to get the current page

HTTPService.getPage('home')
    .success(function ( data ) {
        $scope.page = data.page;
        console.log(arguments);
    })
    .error( function () {
        console.log(arguments);
    })

因此​​,这在所有的浏览器工作正常,除了Safari浏览器的iOS。在Safari上的iOS,我得到以下响应,如果我在错误日志中的参数:

So this is working fine in all browsers, except for safari iOS. On Safari iOS i get the following response if I log the error arguments:

这是Safari的调试器,我连我的iphone到我的MacBook。错误响应,我得到的是错误code 0 ..

This is the safari debugger, I connected my iphone to my macbook. The error response that I get is error code 0..

我至今尝试过

我已经设置`访问控制允许来源*的htaccess的文件,但这似乎没有工作。该请求是在一个相对URL相同的域完成的,所以认为这是问题,我不均匀。

I have set `Access-Control-Allow-Origin "*" in the htaccess file, but this doesnt seem to work. The request is done on the same domain with a relative URL, so I dont even think that this is the problem.

也是如此any1能知道这是为什么不工作的Safari浏览器(仅iOS版)?

So does any1 know why this is not working on safari (iOS only)?

在此先感谢...

修改

的要求,一些额外的信息:

Some extra info as requested:

推荐答案

我是pretty肯定,这是由于这一事实,Safari是有堵第三方cookies和其他的政策,唯一的浏览器网站数据默认情况下。其实,这个问题不应该是排他性的iOS Safari浏览器中,也应该使用Safari发生在你的OSX。我是pretty相信,如果它不是在你的MacBook发生的事情是因为有一天你改变了隐私的默认设置。

I'm pretty sure that this is due to the fact that Safari is the only browser that has the policy of blocking "3rd party cookies and other website data" by default. Actually, this issue shouldn't be exclusive of Safari iOS, it should also happen with Safari on your OSX. I'm pretty sure that if it's not happening in your MacBook is because one day you changed the default settings of the "Privacy".

您可以试试这个,打开Safari,进入preferences和标签不受干扰下检查是否有以下选项:阻止Cookie和其他网站数据设置为从第三方和广告商 。这是第一次,并且在Safari的现代版本的默认选项。

You can try this, open Safari, go to "preferences" and under the tab "Pricacy" check if you have the option: "Block cookies and other website data" set to "From third parties and advertisers". This is the first, and the default option in the modern versions of Safari.

在您的MacBook它看起来是这样的:

In your MacBook it will look like this:

和iOS中它看起来是这样的:

And in iOS it will look like this:

只是为了确认,这其实是什么造成您的问题:更改此设置为从不,清除缓存并尝试再次重现该问题。我非常相信,你将无法重现它。

Just to confirm that this is in fact what's causing your issue: change this setting to "Never", clear the cache and try to reproduce that problem again. I'm quite confident that you won't be able to reproduce it.

现在,如果你将其设置回阻止cookies和其他网站的数据:来自第三方和广告商,你第一个清除缓存后,你将再次有这个问题(带有iOS或OSX)。之后你确认这是你的问题,将该设置回来自第三方和广告商的原因,这样您就可以复制和使用默认设置解决的问题。

Now, if you set it back to "Block cookies and other website data: From third parties and advertisers" and you first clear the cache, you will have that problem again (with either iOS or OSX). After you've confirmed that this is the cause of your problem, set this setting back to "From third parties and advertisers", so that you can reproduce and address the problem with the default settings.

裸记住,要重新测试这个问题,每次你会好起来的结算Safary缓存。否则,它可能发生的Safari浏览器决定了服务于API的网站是可以信任的,你将无法重现该问题。所以,仅仅为了保险起见,清除缓存每一个你测试这个时候。

Bare in mind that every time that you want to re-test this issue you will be better off clearing the cache of Safary. Otherwise it could happen that Safari decides that the site serving the API can be trusted and you won't be able to reproduce the issue. So, just to be sure, clear the cache every time that you test this.

我相信,这个问题的根源是,Safari浏览器要确保用户已与它的服务的主要页面加载的内容之前,第三方内容页面的直接交互。

I believe that the root of this problem is that Safari wants to make sure that the user has had a direct interaction with the page that it's serving the "3rd party content" before the main page loads that content.

我需要更多地了解你的项目,以提出一个最优的解决方案。例如:在最终应用同一个域中的API下进行综合?因为如果是这样的话,当你去生产,你应该不会有问题。我的意思是,如果你正在开发的应用程序将下托管 http://whatever.yourDomain.org 和API将是同一域的一部分( yourDomain.org ),那么你不应该有这个问题在所有的生产。

I would need to know more about your project in order to suggest an "optimal" solution. For instance: will the final app be integrated under the same domain as the API? Because if that's the case, you shouldn't have that issue when you go to production. I mean, if the app that you are developing will be hosted under: http://whatever.yourDomain.org and the API is going to be part of that same domain (yourDomain.org), then you shouldn't have that issue at all in production.

在另一方面,如果你需要有有在不同网域的API,那么你将不得不找到一种方法来绝招Safari浏览器。看看这个:

On the other hand, if you need to have have the API hosted under a different domain, then you will have to find a way to "trick" Safari. Have a look at this:

  • Safari 3rd party cookie iframe trick no longer working?

和这样的:

我希望这会有所帮助。

这篇关于角GET请求的错误,但仅限于iOS的Safari浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆