我想提出一个Chrome扩展为自动登录到无线网络,我使用AJAX做POST请求,但是当我检查它没有POST请求被发送,而不是流行的网络,它只是显示被装载在弹出的文件,和一个jQuery-1.10.1.min.map GET失败。 这是我的popup.html:
<!DOCTYPE HTML>
< HTML>
< HEAD>
<冠军> BCA自动登录< /标题>
<脚本SRC =jquery.js和>< / SCRIPT>
<脚本类型=文/ JavaScript的SRC =login.js>< / SCRIPT>
<风格类型=文本/ CSS>
体{
背景颜色:#2c3e50;
}
标签{
颜色:#f1c40f;
}
< /风格>
< /头>
<身体GT;
<形式方法=POSTID =形式>
<标签>输入用户名
<输入ID =用户名和GT;
< /标签>
< BR>
<标签>输入密码
<输入ID =密码类型=密码>
< /标签>
< BR>
<按钮类型=提交ID =按钮>提交< /按钮>
< /形式GT;
< /身体GT;
< / HTML>
下面是我的manifest.json:
{
manifest_version:2,
名:BCA自动登录,
说明:这个扩展自动登录到你的BCA的wifi,
版本:1.0,
权限:
曲奇饼,
的http:// * / *,
https://开头* / *
]
content_scripts:[{
匹配:[的http:// * / *,https://开头* / *],
JS:[的jquery.js,login.js],
}],
browser_action:{
default_icon:的icon.png,
default_popup:popup.html
}
}
和这里是我的login.js:
$('#形式)。递交(函数(事件){
。事件preventDefault();
VAR URL ='https://ccahack.bergen.org/auth/perfigo_validate.jsp';
$阿贾克斯({
键入:POST,
网址:http://whatsmywork.appspot.com/auth/perfigo_validate.jsp,
数据 : {
reqFrom:perfigo_simple_login.jsp,
URI:https://ccahack.bergen.org/,
厘米:ws32vklm,
USERIP:IP,
操作系统:MAC_OSX,
索引:'4',
用户名:用户,
密码:'通',
供应商:FDS,
login_submt:继续
}
});
});
解决方案
您试图附加该事件的文件已经准备好了。附上code在 login.js 的 $(函数(){
和});
I am making a chrome extension to auto login into the wifi, I use AJAX to do the post request but when I check the network of the pop it no POST request is sent instead, it just shows the popup files being loaded, and a jquery-1.10.1.min.map GET failed. Here is my 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>
Here is my 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"
}
}
And here is my 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'
}
});
});
解决方案
You are trying to attach the event before the document is ready. Enclose the code in your login.js between $(function() {
and });