我有以下 JavaScript 代码:
App.Views.AddPerson = Backbone.View.extend({
el: '#addPerson',
events: {
'submit': 'submit',
},
submit: function (e) {
e.preventDefault();
var newPersonName = $(e.currentTarget).find('input[type=text]').val();
var person = new App.Models.Person({ name: newPersonName, age: newAge, occupation: newOccupation });
this.collection.add(person);
this.$('#todo-title').val('');
$.ajax({
type: 'POST',
url: '@Url.Action("InsertRecord", "Home")',
data: newPersonName ,
success: function(data) {
alert(data);
},
error: function(){
alert("error");
}
});
}
});
在控制器中,我有以下方法:
[HttpPost]
public ActionResult InsertRecord(string str)
{
return View();
}
但它不执行 ajax 调用并引发错误。