我在 Bootstrap 模式的主体中有以下形式:
<form id="contact" class="contact" name="contact">
<fieldset>
<!-- Form Name -->
<legend>Free Contact</legend>
<!-- Text input-->
<div class="control-group">
<label class="control-label" for="To">To</label>
<div class="controls">
<input id="To" name="To" placeholder="placeholder" class="input-xlarge" required="" type="text">
</div>
</div>
<!-- Textarea -->
<div class="control-group">
<label class="control-label" for="Message">Message</label>
<div class="controls">
<textarea id="Message" name="Message"></textarea>
</div>
</div>
<!--Button (Double)-->
<div class="control-group">
<label class="control-label" for="Send"></label>
<div class="controls">
<button id="Send" name="Send" class="btn btn-success">Send</button>
<button id="Cancel" name="Cancel" class="btn btn-danger">Cancel</button>
</div>
</div>
</fieldset>
</form>
<script>
$("input#Send").click(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: "Update/contact", //process to mail
data: $('form.contact').serialize(),
success: function(msg){
console.log($('form.contact').serialize);
},
error: function(){
alert("failure");
}
});
});
</script>
表单正在提交,但未提交到正确的 codeigniter Controller 和函数。它似乎从模态所在的 codeigniter View 中获取 URL,并附加序列化的表单值,忽略我的 jquery post 请求。我做错了什么?
最佳答案
尝试改变你的ajax
$("#Send").click(function(e){
e.preventDefault();
$.ajax({
type: "POST",
dataType: "html"
url: "Update/contact", //process to mail
data: $('form.contact').serialize(),
success: function(data){
console.log($('form.contact').serialize();
},
error: function(){
alert("failure");
}
});
});
您忘记了序列化时的(
。
关于javascript - 如何从模态提交 Bootstrap 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27133631/