我试图从服务器上的目录中获取图像数量。我使用PHP来计算图像的数量,并使用AJAX(在我的chrome扩展中)来获取外部PHP文件中的图像数量。
正在经历成功:{} ,但未运行 if(data){} 。它偶尔会警告错误,说出现以下错误:错误。我该如何解决这个问题?
main.js
Publish
的manifest.json
...
(function ($) {
$(document).ready(function(e) {
$.ajax({
url: 'http://website.com/numberOfImages.php', // <== POINTS TO THE VALID URL OF THE PHP FILE THAT OUTPUTS THE NUMBER OF IMAGES...
dataType: "HTML",
cache: false,
type: "POST",
//HANDLE THE SUCCESS CASE FOR THE AJAX CALL
success: function (data, textStatus, jqXHR) {
if(data){
alert(data);
}
},
//HANDLE THE FAILURE CASE FOR THE AJAX CALL
error: function (jqXHR, textStatus, errorThrown) {
alert('The following error occurred: ' + textStatus, errorThrown);
},
//HANDLE THE EVENT-COMPLETE CASE FOR THE AJAX CALL
complete: function (jqXHR, textStatus) {
}
});
});
})(jQuery);
numberOfImages.php
{
"name": "some name",
"description": "Add description",
"version": "1.0",
"permissions": [
"activeTab"
],
"chrome_url_overrides" : {
"newtab": "main.html"
},
"background": {
"scripts": ["jquery-2.2.3.min.js", "background.js"],
"persistent": false
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/",
"storage",
"tabs",
"http://*/*",
"https://*/*"
],
"browser_action": {
"default_title": "some title"
},
"manifest_version": 2
}
答案 0 :(得分:0)
@PatrickEvans评论回答了我的问题。感谢。
我的更新代码:
<?php
$dir = "/home/some/directory";
$fi = new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS);
$fileCount = iterator_count($fi);
echo $fileCount;
?>