Forms JQuery表单提交功能不起作用
我对jquery函数提交表单有问题:Forms JQuery表单提交功能不起作用,forms,submit,form-submit,Forms,Submit,Form Submit,我对jquery函数提交表单有问题: $(document).ready(function () { $('#message').keydown(function(e) { if(e.which == 13 && !e.shiftKey) { $('#edit_message_11').submit(function() { alert("HELLO2"); });
$(document).ready(function () {
$('#message').keydown(function(e) {
if(e.which == 13 && !e.shiftKey) {
$('#edit_message_11').submit(function() {
alert("HELLO2");
});
return false;
}
});
});
<form id="edit_message_11" class="edit_message" method="post" action="/message/11" accept-charset="UTF-8">
<textarea id="message" class="form-control edit_message_form" name="message">
Hello
</textarea>
$(文档).ready(函数(){
$(“#消息”).keydown(函数(e){
if(e.which==13&&!e.shiftKey){
$('#编辑_消息_11')。提交(函数(){
警惕(“HELLO2”);
});
返回false;
}
});
});
你好
当我对表单执行以下操作时:$('edit#u message_11').submit(function(){…})它不会触发提交
但是,如果我执行$('edit#u message_11')。submit()它确实会触发提交
我需要执行$('edit#u message_11').submit(function(){…})的原因是因为我想做一个ajax提交
有人有线索吗
谢谢 我不相信它会像你尝试的那样起作用。当它位于submit函数中时,警报将永远不会触发,直到它从POST获得响应为止。这意味着您需要表单处理脚本的响应 AJAX调用不需要在submit函数中,只需要在事件中
$(document).ready(function () {
$('#selfie_message').keydown(function(e) {
if(e.which == 13 && !e.shiftKey) {
$('#edit_selfie_11').submit();
$.ajax({
type: "POST",
url: "/selfies/11",
data: $("#edit_selfie_11").serialize()
});
}
});
});
如果你想成功,你会这样做
$(document).ready(function () {
$('#selfie_message').keydown(function(e) {
if(e.which == 13 && !e.shiftKey) {
$('#edit_selfie_11').submit();
$.ajax({
type: "POST",
url: "/selfies/11",
data: $("#edit_selfie_11").serialize(),
success: function(response){
//your response code here//
}
});
}
});
});
抱歉,正确的链接是:非常感谢!我想我在很多其他帖子中看到了submit(function())中的“alert”,它似乎对他们有用。不过,您的解决方案非常有效。再次感谢你的帮助!