我正在制作镀铬扩展程序以自动登录wifi,我使用AJAX来执行发布请求但是当我检查pop的网络时,没有发送POST请求,它只显示正在加载的弹出文件,和一个jquery-1.10.1.min.map GET失败了。 这是我的popup.html:
<!doctype html>
<html>
<head>
<title>BCA Auto Login</title>
<script src="jquery.js"></script>
<script type="text/javascript" src="login.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" id="button">Submit</button>
</form>
</body>
</html>
这是我的manifest.json:
{
"manifest_version": 2,
"name": "BCA Auto Login",
"description": "This extension automatically signs you into the BCA wifi",
"version": "1.0",
"permissions": [
"cookies",
"http://*/*",
"https://*/*"
],
"content_scripts": [{
"matches": ["http://*/*","https://*/*"],
"js": ["jquery.js","login.js"],
}],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
这是我的login.js:
$('#form').submit(function (event) {
event.preventDefault();
var url = 'https://ccahack.bergen.org/auth/perfigo_validate.jsp';
$.ajax({
type : 'POST',
url : 'http://whatsmywork.appspot.com/auth/perfigo_validate.jsp',
data : {
reqFrom: 'perfigo_simple_login.jsp',
uri: 'https://ccahack.bergen.org/',
cm: 'ws32vklm',
userip: 'IP',
os: 'MAC_OSX',
index: '4',
username: 'user',
password: 'pass',
provider: 'fds',
login_submt: 'Continue'
}
});
});
答案 0 :(得分:3)
您正在尝试在文档准备好之前附加事件。将{strong> login.js 中的代码包含在$(function() {
和});