Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/452.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Chrome扩展中使用JQuery_Javascript_Jquery_Json_Google Chrome_Google Chrome Extension - Fatal编程技术网

Javascript 在Chrome扩展中使用JQuery

Javascript 在Chrome扩展中使用JQuery,javascript,jquery,json,google-chrome,google-chrome-extension,Javascript,Jquery,Json,Google Chrome,Google Chrome Extension,我正在为minecraft服务器创建一个chrome扩展。此扩展的目的是返回服务器的联机状态。我正在使用JQuery的getJSON函数来解析位于Web服务器上的JSON文件的状态,当我在浏览器中将其作为实际网页运行时,它可以正常工作,但我无法让它在扩展中工作 manifest.json { "manifest_version": 2, "name": "CJFreedom", "description": "Displays the status of the Minecraft

我正在为minecraft服务器创建一个chrome扩展。此扩展的目的是返回服务器的联机状态。我正在使用JQuery的getJSON函数来解析位于Web服务器上的JSON文件的状态,当我在浏览器中将其作为实际网页运行时,它可以正常工作,但我无法让它在扩展中工作

manifest.json

{
  "manifest_version": 2,

  "name": "CJFreedom",
  "description": "Displays the status of the Minecraft server CJFreedom.",
  "version": "1.0",


  "permissions": [
    "https://www.thecjgcjg.com/panel/scripts/stats.php",
    "https://www.thecjgcjg.com/",
    "https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"
  ],

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  }
}
popup.html

<html>
<head>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="popup.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">

</head>
<body>
    <img src="header.png" alt="diz iz header" width="300px"> <br/>
    <a href="http://www.twitter.com/CJFupdates" target="_blank"><img src="twitter.png" alt="Follow CJFreedom on twitter" width="16px" style="float: right; margin: 5px;"></a>
        <p style="float: right;">Follow: </p>

    <div id="content">
        <p style="float: left;" id="status"> CJFreedom is <span style="color: orange;">?...</span></p> <br />
        <p> IP: <b>play.thecjgcjg.com </b></p>
        <p> Forum: <b><a href="http://www.thecjgcjg.com/forum/" target="_blank">thecjgcjg.com/forum</a></b></p>
    </div>
</body>
</html>


如下所示:

自由是什么 IP:play.thecjgcjg.com

论坛:

popup.js

$.getJSON("https://www.thecjgcjg.com/panel/scripts/stats.php", function(result){
    status = result.status;

    if (status == "Offline")
        $('#status').html('CJFreedom is <span style="color: red;"><b>Offline</b>.(</span>');
    else
        $('#status').html('CJFreedom is <span style="color: #3AC400;"><b>Online</b>!</span>');

});
$.getJSON(“https://www.thecjgcjg.com/panel/scripts/stats.php,函数(结果){
状态=结果。状态;
如果(状态=“脱机”)
$('#status').html('CJFreedom处于脱机状态。');
其他的
$(#status').html('CJFreedom is Online!');
});

正如您所看到的,当扩展解析JSON文件时,状态为“?…”,当服务器启动时,状态为“联机”,当服务器关闭时,状态为“脱机”。正如我前面提到的,当我在浏览器中将其作为网页运行时,它工作正常,但当我打开扩展时,它卡在“?…”位置部分,好像它只是忽略了javascript…

您可能遇到了一个问题,它阻止了外部脚本的加载

您是否尝试过下载jQuery文件并将其作为扩展的一部分,就像任何其他JavaScript文件一样?这在过去对我来说非常有效,并且支持“离线优先”模式,这通常是Chrome应用程序和扩展的首选模式。这在下面的“捆绑”部分中提到:

如果要使用浏览器不提供的库(例如jQuery),可以将该库的JavaScript文件与扩展捆绑在一起。捆绑的库在扩展中工作,就像在其他网页中一样