如何在Chrome扩展程序中执行POST请求?

时间:2013-11-22 12:41:47

标签: javascript google-chrome jquery google-chrome-extension

我正在制作Chrome扩展程序,以便将帖子请求发送到某个网址,我不关心响应。当我在浏览器中运行我的javascript它工作正常,但如果我放入chrome扩展名,它甚至不发送。这是我的popup.html文件

<!doctype html>
<html>
    <head>
        <title>BCA Auto Login</title>
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <style type="text/css">
        body{
            background-color: #2c3e50;
        }
        label{
            color:#f1c40f;
        }
        </style>
    </head>
    <body>
        <form method="POST" id="form">
            <label>Enter username
                <input id="username">
            </label>
            <br>
            <label>Enter password
                <input id="password" type="password">
            </label>
            <br>
            <button type="submit">Submit</button>
        </form>
    <script type="text/javascript">
        $('#form').submit(function (event) {
            event.preventDefault();
            $.ajax({
                type : 'POST',
                url : 'https://testurl.com/',
                data : {
                    reqFrom: 'perfigo_simple_login.jsp',
                    uri: 'https://ccahack.bergen.org/',
                    cm: 'ws32vklm',
                    userip: '168.229.105.180',
                    os: 'MAC_OSX',
                    index: '4',
                    username: 'username',
                    password: 'password',
                    provider: 'BCA',
                    login_submt: 'Continue'
                }
            }); 
        });
    </script>
    </body>
</html>

这是我的mainfest.json:

{
  "manifest_version": 2,

  "name": "Auto Login",
  "description": "This extension automatically signs you into the wifi",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "permissions": [
    "cookies",
    "http://*/*"
    "https://*/*"
  ]
}

0 个答案:

没有答案