我有一个模块的骨架,它通过单击按钮将记录添加到数据库中。
var Person = (function () {
var ajaxOpts = {
type: "POST",
url: "",
contentType: "application/json",
dataType: "json",
success: function () { },
error: function () { },
data: {}
}
function insert(data) {
ajaxOpts.url = "../Service.asmx/InsertPerson";
ajaxOpts.data = JSON.stringify(data);
ajaxOpts.error = function (xhr) {
console.log(xhr.status);
};
ajaxOpts.success = function (data) {
console.log('record successfully added');
console.log(data.d);
}
$.ajax(ajaxOpts);
};
return {
insert: insert
}
} ());
我从我的网页上调用它,例如:
$(document).ready(function () {
$('#btnSubmit').click(function () {
var data = {
personId: $('#personId').val(),
firstName: $('#firstName').val(),
lastName: $('#lastName').val()
};
Person.insert(data);
});
});
如何修改此代码以确保它$
是 jQuery 对象而不是另一个库?