我正在制作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'
}
});
}); …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试从HTML中的表单中获取值,并通过对URL进行GET请求来获取HTML,然后使用jquery解析该HTML.
这是我想要解析的HTML:
<!doctype html>
<title>Test</title>
<body>
<form name="guestform">
<input type="hidden" name="ip" value="198.168.123">
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
这是我用来获取HTML然后尝试解析它的jquery:
$.ajax({
type : 'GET',
url: "http://localhost:8000/test.html",
success: function(data){
var form = $(data);
var ip = $("input[name='ip']").find(form).val();
alert(ip);
}
});
Run Code Online (Sandbox Code Playgroud) 我正在制作镀铬扩展程序以登录到wifi系统,并且目前已将其设置为必须单击扩展程序才能登录.但我希望它只需每30分钟签名一次,使用背景js我想要它检查我保存的cookie,如果已经过了30分钟,然后登录.但是只有在你第一次安装它时它才有用.
这是我的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"]
}],
"background": {
"scripts": ["jquery.js", "background.js"]
},
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的background.js:
$(document).ready(function(){
chrome.cookies.get({ url: 'urlofCookie.com', name: 'time' },
//the cookie is a time in minutes
function (cookie) {
if (cookie) {
var current = new Date();
if((current.getMinutes() - cookie) >= 30){
$.ajax({ …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试编写一个简单的C程序,它创建一个带有char*字段的结构,并将其赋值为与argv [1]相同的值.然后我想创建另一个与argv [1]长度相同的char*,但由于某种原因,里面的数据已经包含与argv [1]相同的值.到目前为止,这是我的代码:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
struct example{
char *str;
};
struct example* create(char *s){
struct example *p = (struct example*)malloc(sizeof(struct example));
char * copy = (char*)malloc(strlen(s));
strcpy(copy, s);
p->str = copy;
free(copy);
return p;
}
void new_char(struct example * t){
printf("original: %s\n", t->str);
char *w = (char *)malloc(strlen(t->str));
printf("why is this a copy? %s\n", w);
free(w);
}
void clean(struct example *t){
free(t);
}
int main(int argc, char **argv){
struct example * p = …Run Code Online (Sandbox Code Playgroud)