我想使用JS和AJAX(在我的chrome扩展中)获取目录中的图像数量。我怎样才能做到这一点?我在下面添加了当前的代码。它似乎没有起作用,因为我没有收到警报。
main.js
...
$.ajax({
url: "/images-folder-on-server/",
success: function (data) {
var image_count = $(data).length();
alert(image_count);
}
});
main.html中
<html>
<head>
<title>New Tab</title>
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="/octicons/octicons.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="jquery.min.js"></script>
</head>
<body>
<h1 id = "greet">Hello,''.</h1>
<div id="clock"></div>
<script src = "main.js"></script>
</body>
</html>
的manifest.json
{
"name": "Name",
"description": "Add description",
"version": "1.0",
"permissions": [
"activeTab"
],
"chrome_url_overrides" : {
"newtab": "main.html"
},
"background": {
"scripts": ["jquery.min.js", "main.js"],
"persistent": false
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/",
"storage",
"tabs",
],
"browser_action": {
"default_title": "Background image"
},
"manifest_version": 2
}
答案 0 :(得分:0)
假设您的ajax呼叫来自后台页面,请不要忘记将远程服务器URL添加到permissions
。
"permissions": ["Complete_Images_Server_Url"]