Spotify 应用程序和 jQuery

发布于 2024-12-20 23:24:47 字数 505 浏览 2 评论 0原文

如何在我的 Spotify 应用程序中添加和使用 jQuery(使用 Spotify 应用程序 API)?

关于这篇文章 http://docs.jquery.com/Using_jQuery_with_Other_Libraries 我在我的 Spotify 应用程序中尝试了这个:

<body onload="sp = getSpotifyApi(1); j = sp.require('jquery'); tutorial = sp.require('tutorial'); tutorial.init();">

然后:

var $j = j.jQuery.noConflict();
$j("h2").text("ddd");

但这不起作用......

How can I add and use jQuery in my Spotify App (using Spotify Apps API)?

Regarding this this article http://docs.jquery.com/Using_jQuery_with_Other_Libraries I tried this in my Spotify App:

<body onload="sp = getSpotifyApi(1); j = sp.require('jquery'); tutorial = sp.require('tutorial'); tutorial.init();">

And then :

var $j = j.jQuery.noConflict();
$j("h2").text("ddd");

But it doesn't works...

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

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

发布评论

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

评论(5

枫林﹌晚霞¤ 2024-12-27 23:24:47

为什么不在 head 中添加 jQuery.js 文件?

因此,如果您学习教程 http://developer.spotify.com/download/ Spotify-apps-api/tutorial/ 它将更改为

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>My First App</title>
    <link rel="stylesheet" href="sp://import/css/adam.css">
    <link rel="stylesheet" href="tutorial.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
</head>
<body>
<h1 id="header">Hello, world!</h1>
</body>
</html>

why not adding the jQuery.js file within the head?

so if you take the tutorial http://developer.spotify.com/download/spotify-apps-api/tutorial/ it would change to

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>My First App</title>
    <link rel="stylesheet" href="sp://import/css/adam.css">
    <link rel="stylesheet" href="tutorial.css">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
</head>
<body>
<h1 id="header">Hello, world!</h1>
</body>
</html>
跨年 2024-12-27 23:24:47

通过插件中的脚本标签使用 jquery 的方法是下载 jquery,将其保存到插件文件夹中,然后像这样简单地调用它:

<script type="text/javascript" src="jquery.js"></script>

这是有道理的,因为指南说:

[...]您必须确保将所有逻辑/布局/图形/等捆绑在一起
您的应用程序包,以便在运行时无法替换它[...]
简而言之 - 只从您自己的后端请求动态数据,然后让
所有其他数据都进入应用程序包本身。

这应该意味着只能向外部位置发出 POST/GET 请求,并且只能向清单所需权限列表中列出的位置发出请求。
我确信可以通过在清单中允许 ajax.googleapis.com 、通过外部调用下载 jquery 并通过一些邪恶的 eval 函数运行它之类的操作来解决这个问题..但我真的没有看到任何意义。

使用 CDN 对于网站来说非常有用,您最好让用户使用先前从同一 CDN 下载的 jquery 缓存版本,以节省加载时间。然而,在 Spotify 应用程序中,远程托管 jquery 并没有真正的利润,即使该应用程序的每个用户始终连接到互联网。

For using jquery through a script tag in in an addon is to download jquery, save it to your addon folder and simply calling it like so:

<script type="text/javascript" src="jquery.js"></script>

This makes sense since the guidelines say:

[...]you must make sure to bundle all logic/layout/graphics/etc within
your app bundle so that it can’t be replaced during runtime[...]
In short - only request dynamic data from your own backend, and let
all other data go into the app bundle itself.

That should mean only POST/GET requests can be made to external places and only to places listed in the manifest RequiredPermissions list.
I'm sure it's possible to hack around this by doing something like allowing ajax.googleapis.com in the manifest, downloading the jquery through an external call and running it through some evil eval function.. but I don't really see any point.

Using a CDN is mostly useful for websites where you'd ideally have users use a cached version of jquery downloaded from the same CDN at an earlier time in order to save load times. In the spotify app case however, there's no real profit in hosting jquery remotely, even if every user of the app is always connected to the internet.

迷爱 2024-12-27 23:24:47

将其放在文档的顶部对我来说很有用。如果我的应用程序是社交应用程序并且 jquery 驻留在 /js/jquery-1.7.1.min.js 中,请编写以下内容

sp.require("sp://social/js/jquery-1.7.1.min");

It works for me to put this in the top of the document. If my app is social and jquery resides in /js/jquery-1.7.1.min.js write following

sp.require("sp://social/js/jquery-1.7.1.min");
ら栖息 2024-12-27 23:24:47

您可以通过在 index.html 上包含脚本标记来使用 jQuery,但建议您从应用程序内的本地副本加载 jquery.js - 否则您必须将 code.jquery.com suddomain 添加到RequiredPermissions您的manifest.json 上的数组。

You can use jQuery by including a script tag on your index.html, but it's recommended that you load the jquery.js from a local copy within your app - otherwise you'll have to add the code.jquery.com suddomain to the RequiredPermissions array on your manifest.json.

一页 2024-12-27 23:24:47

我认为您不允许通过脚本标签访问外部文件。不过,如果您下载 jquery.js 并将其放入您的应用程序文件夹中,您将能够按照示例所示的方式访问它。

I don't think you're allowed to access external files through a script-tag. Although, if you download the jquery.js and put it in your app folder you will be able to access it the way your example shows.

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