我无法在Chrome扩展程序中提交表单以提交:
这是main.js
文件:
$(function() {
$('form').submit(function(e){
e.preventDefault(); // prevents the default action (in this case, submitting the form)
$('#status').hide();
$.post(
'http://www.domain.com/?i=ajax',
$('form').serialize(),
function (data) {
proccessData(data);
}
);
return false;
});
});
function proccessData (data) {
alert("Submitted!");
if(data=='success'){
$('form').hide();
$('#status').addClass('noti success').html('<p>Your reply has been added.</p>').show();
}
else {
$('#status').removeClass().addClass('noti error').html('<p>'+data+'</p>').fadeIn();
}
}
这是我的popup.html
文件:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery.js"></script>
<script src="main.js"></script>
</head>
<body>
<form method="post" action="http://www.domain.com/?i=ajax">
<label for="url">Test</label>
<input id="urlname" name="url" type="text" value="" />
<input type="submit" value="Send" />
</form>
<div id="status"></div>
</div>
</body>
</html>
manifest.json
文件:
{
"name": "My App",
"version": "0.0.1",
"manifest_version": 2,
"browser_action": {
"default_icon": {
"19": "icons/19x19.png",
"38": "icons/38x38.png"
},
"default_title": "Quick Dashboard - domain Addon",
"default_popup": "popup.html"
},
"permissions": [
"http://www.domain.com/"
]
}
提交表单时没有任何反应。我也没有看到开发工具中的错误。
答案 0 :(得分:0)
您是否在开发者工具中检查过netowrk选项卡?见http://i.imgur.com/nJEtgaW.png。它应该告诉您请求的状态。对于我的代码,我使用http://requestb.in/发出POST
请求。看看这有帮助吗?
var request = $.ajax({
url: "http://www.domain.com/",
type: "POST",
data: {
i : "ajax"
}
});
request.done(function (response) {
console.log(response);
});
request.fail(function(jqXHR, status) {
console.log(status);
});