我正在尝试使用淘汰赛将我的表格提交给休息服务。按下submit
按钮后,表单进入无限循环,直到浏览器崩溃。无法真正理解这里发生了什么。
Javascript:
var viewModel;
var Subscription = function () {
var self = this;
self.Name = ko.observable('');
self.Email = ko.observable('');
self.submitForm = function () {
var viewModelJs = ko.toJS(ko.utils.unwrapObservable(viewModel));
$.ajax('/umbraco/surface/newsletter/AddSubscription', {
data: viewModelJs,
type: "POST",
async: true,
contentType: "application/json",
dataType: "json",
success: function (result) {
alert("sent");
},
error: function (error) {
if (window.console && console.log) {
console.log(error);
}
}
});
return false;
};
};
$(function () {
viewModel = new Subscription();
ko.applyBindings(viewModel);
});
这是我的表格:
<form class="form-horizontal" data-bind="submit: $root.submitForm">
<div class="control-group">
<label class="control-label" for="Name">Nombre</label>
<div class="controls">
@Html.TextBoxFor(m => m.Name, new { placeholder = "Nombre", data_bind = "value: Name" })
@Html.ValidationMessageFor(m => m.Name)
</div>
</div>
<!-- A couple more controls here -->
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Enviar</button>
</div>
</div>
</form>