英文:
Form not sending, POST
问题
I have my form
<form class="newsletter" action="https://sendy.thegoodfellas.net/sendy/subscribe" method="POST" accept-charset="utf-8">
<span class="container active">
<label for="name">What's your name?</label>
<input class="required" type="text" name="name" id="name"/>
<span class="next" title="next"></span>
</span>
<span class="container">
<label for="email">What's your email?</label>
<input class="required" type="email" name="email" id="email"/>
</span>
<span class="submit" type="submit" name="submit" id="submit"></span>
</form>
and the JS
$('.next').click(function(){
var nextTarget = $(this).parent().siblings('span');
var currentTarget = $(this).parent();
currentTarget.removeClass('active');
nextTarget.addClass('active').find('input').focus();
});
$('input#email').on('keydown',function(e){
var keyCode = e.keyCode || e.which;
if (keyCode == 13) {
$('.submit').trigger('click');
}
})
$('.submit').click(function(){
var target = $(this);
var lastInputContainerLabel = target.parent().find('.container.active label');
target.addClass('submitted');
lastInputContainerLabel.addClass('fadeOut');
})
But for some reason, when the form is submitted I do not see the post call in the network. Nothing is sent.
https://thegoodfellas.net/beatsoutsideblockparty/
How should I debug it?
英文:
I have my form
<form class="newsletter" action="https://sendy.thegoodfellas.net/sendy/subscribe" method="POST" accept-charset="utf-8">
<span class="container active">
<label for="name">What's your name?</label>
<input class="required" type="text" name="name" id="name"/>
<span class="next" title="next"></span>
</span>
<span class="container">
<label for="email">What's your email?</label>
<input class="required" type="email" name="email" id="email"/>
</span>
<span class="submit" type="submit" name="submit" id="submit"></span>
</form>
and the JS
$('.next').click(function(){
var nextTarget = $(this).parent().siblings('span');
var currentTarget = $(this).parent();
currentTarget.removeClass('active');
nextTarget.addClass('active').find('input').focus();
});
$('input#email').on('keydown',function(e){
var keyCode = e.keyCode || e.which;
if (keyCode == 13) {
$('.submit').trigger('click');
}
})
$('.submit').click(function(){
var target = $(this);
var lastInputContainerLabel = target.parent().find('.container.active label');
target.addClass('submitted');
lastInputContainerLabel.addClass('fadeOut');
})
But for some reason, when the form is submitted I do not see the post call in the network. Nothing is sent.
https://thegoodfellas.net/beatsoutsideblockparty/
How should I debug it?
答案1
得分: 1
This line of HTML:
<span class="submit" type="submit" name="submit" id="submit"></span>
不合法。type="submit" 不是元素的已识别属性。
你真正有两个选择:
a) 将你的 "submit" 元素改为元素(并根据需要进行样式设置),或者 b) 在你的JavaScript代码中添加一行额外的代码来实际提交表单。
$('.submit').click(function(){
var target = $(this);
var lastInputContainerLabel = target.parent().find('.container.active label');
target.addClass('submitted');
lastInputContainerLabel.addClass('fadeOut');
document.forms[0].submit();
})
或者,如果给你的 "submit" 元素一个ID,然后你可以通过该ID直接引用它(如果你的页面中有多个表单,这特别有用,以确保你提交的是正确的一个)。
例如:
<span class="submit" id="submitSpan">Submit Me</span>
document.getElementById('submitSpan').submit();
英文:
This line of HTML:
<span class="submit" type="submit" name="submit" id="submit"></span>
is not valid. type="submit" is not a recognised attribute of a <span> element.
You really have two choices:
a) change your <span> "submit" element to an <input> element (and style it as required), or b) add an extra line in your javascript code to actually submit the form
$('.submit').click(function(){
var target = $(this);
var lastInputContainerLabel = target.parent().find('.container.active label');
target.addClass('submitted');
lastInputContainerLabel.addClass('fadeOut');
document.forms[0].submit();
})
Alternatively, if you give your <span> "submit" element an ID then you could reference it directly by the ID (particularly useful if you have multiple forms within your page, to be doubly sure you're submitting the correct one)
eg.
<span class="submit" id="submitSpan">Submit Me</span>
document.getElementById('submitSpan').submit();
答案2
得分: 1
你没有提交表单,将 $("form.newsletter").submit();
添加到 $('.submit').click
函数中。
$('.submit').click(function(){
var target = $(this);
var lastInputContainerLabel = target.parent().find('.container.active label');
target.addClass('submitted');
lastInputContainerLabel.addClass('fadeOut');
//---添加这部分------
$("form.newsletter").submit();
})
英文:
You did not submit your form, add $("form.newsletter").submit();
in $('.submit').click
function.
$('.submit').click(function(){
var target = $(this);
var lastInputContainerLabel = target.parent().find('.container.active label');
target.addClass('submitted');
lastInputContainerLabel.addClass('fadeOut');
//---Add this------
$("form.newsletter").submit();
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论