Javascript 小部件在我自己的域上工作正常,但在其他人的域上却不行?

发布于 2024-12-07 01:11:01 字数 323 浏览 2 评论 0原文

创建了 javascript 小部件。在我自己的域上进行测试并且工作正常。然而,当在第三方网站上发布时,它似乎没有连接到数据库并获取数据。

这是我获取数据的 js 文件部分:

/******* Load HTML *******/
var jsonp_url = "http://www.example.com/widget/data.php";
$.getJSON(jsonp_url, function(data) {

当我在 example.com 上测试时,一切正常。我将 data.php 的权限设置为 777,但它仍然不起作用。请帮忙!

Created javascript widget. Testing on my own domain and its working fine. However when posting on a 3rd party site it looks like it's not connecting to the database and getting the data.

Here is the part of the js file where I get the data:

/******* Load HTML *******/
var jsonp_url = "http://www.example.com/widget/data.php";
$.getJSON(jsonp_url, function(data) {

When I test on example.com everything is fine. I set the permissions on data.php to 777 and it still isn't working. Please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

征﹌骨岁月お 2024-12-14 01:11:01

您不能跨不同域进行 ajax 调用:
假设您的域名是“example.com”,第三方网站的域名是“thirdparty.com”。您在thirdparty.com 上安装该小部件。 Thirdparty.com 上的小部件代码将尝试向“example.com”发出 ajax 请求。这是浏览器禁止的。

您始终可以用直接的 < 来替换 ajax 调用。脚本>标签。这没有任何限制。

希望有帮助

you cannot make an ajax call across different domains:
let's say your domain is 'example.com', and the third party site has 'thirdparty.com'. you install the widget on thirdparty.com. The widget code on thirdparty.com will try to make an ajax request to 'example.com'. Which is forbidden by the browser.

You can always replace the ajax call with a straight < script > tag. This doesn't have any restriction.

Hope it helps

吻泪 2024-12-14 01:11:01

您有一个名为 jsonp_url 的变量,但您使用的 URL 不包含字符串 callback=?,其中 文档说触发 jsonp 模式

您需要将其包含在 URL 中,并确保您的服务器端脚本输出 JSONP(使用 $_GET['callback'] (经过适当的清理)来确定将 JSON 包装在其中的函数名称)。

You have a variable called jsonp_url, but the URL you use doesn't include the string callback=? which the documentation says triggers jsonp mode.

You need to include that in the URL and make sure that your server side script is outputting JSONP (using $_GET['callback'] (with suitable sanitisation) to determine the function name you wrap the JSON in).

东走西顾 2024-12-14 01:11:01

他们需要启用跨源资源共享。 http://enable-cors.org/

they need to enable cross orgin resource sharing. http://enable-cors.org/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文