數據假設要插入到數據庫中,但沒有。任何進程之前,JQuery都會提示失敗的操作我認爲url根本不會向控制器發送請求,任何人都可以告訴我這段代碼中的錯誤在哪裏。數據未插入到數據庫中
public class EmployeeController : ApiController {
static EmpRepository repository = new EmpRepository();
public string AddEmployee(Employee em) {
var response = repository.AddEmployees(em);
return response;
}
}
的Jquery:
function AddEmp() {
var Emp = {};
Emp.FirstName = $("#fname").val();
Emp.LastName = $("#lname").val();
Emp.Company = $("#company").val();
$.ajax({
url = 'api/AddEmployee';
tpye: "post",
contentType: "application/json;charset=utf-8",
data: JSON.stringify(Emp),
dataType: "JSON",
success: function (response) {
alert(response);
},
error: function(x, e){
alert('Failed');
alert(x.response);
//alert(x.status);
}
});
}
$(document).ready(function() {
$("#save").click(function (e){
AddEmp();
e.preventDefault();
});
});
我想知道爲什麼有人在沒有任何理由的情況下回答這個問題 –
爲什麼你不把你的網址添加到$ .ajax調用? – Omidam81
:),你編輯了你的代碼? – Omidam81