0

私のマニフェストコードは

 {
  "name": "Sample",
  "description": "Sample demonstration",
  "version": "0.1",
  "minimum_chrome_version": "16.0.884",
  "permissions": [
    "experimental", "tabs","<all_urls>"
  ],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "manifest_version": 2
}

私のpopup.htmlのコードは

<html>
<head>
<script src='popup.js'></script>
<script src='jquery.js'></script>
</head>
<body>
</body>
</html>

popup.jsコード

$(document).ready(function() {
     $.post('http://localhost/LinkBook/index.php', {}, function(res){
                       console.log('res');
                    });   
    });

しかし、それは機能していません。手伝ってください。

4

1 に答える 1

1

私はすべての投稿リクエストのサンプルスケルトンを作成しました。これは十分にテストされ、何年にもわたって機能しています。これを参照として使用し、コードを修正できます

マニフェスト.json

{
  "name": "Sample",
  "description": "Sample demonstration",
  "version": "0.1",
  "minimum_chrome_version": "16.0.884",
  "permissions": [
    "experimental", "tabs","<all_urls>"
  ],
  "browser_action": {
    "default_icon": "icon.jpg",
    "default_popup": "popup.html"
  },
  "manifest_version": 2
}

popup.html

<html>
<head>
<script src='transaction.js'></script>
</head>
<body>
</body>
</html>

popup.js

function searchquotes(){

var xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function(data) {
    if (xhr.readyState == 4) {
      if (xhr.status == 200) {
            console.log("Response is recieved");
        }
      } else {
        //callback(null);
      }
    }

var url = 'https://'+'somedomain.com/sompage.php';
xhr.open('POST', url, true);
xhr.send();

}
window.onload = searchquotes;

jqueryバージョン

IMP:コードに含めることはできません<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>。jqueryをダウンロードしてルートフォルダーを基準にして配置してください。詳細については、こちらを確認してください(https://developer.chrome.com/extensions/contentSecurityPolicy.html)

マニフェスト.json

{
  "name": "Sample",
  "description": "Sample demonstration",
  "version": "0.1",
  "minimum_chrome_version": "16.0.884",
  "permissions": [
    "experimental", "tabs","<all_urls>"
  ],
  "browser_action": {
    "default_icon": "icon.jpg",
    "default_popup": "popup.html"
  },
  "manifest_version": 2
}

popup.html

<html>
<head>
<script src='transaction.js'></script>
<script src='jquery.js'></script>
</head>
<body>
</body>
</html>

transaction.js

$(document).ready(function() {
     $.post("http://somedomain.com/sompage.php', {}, function(res){
                       console.log(res);
                    });   
    });
于 2012-11-26T02:20:32.890 に答える