【发布时间】:2013-12-14 18:34:39
【问题描述】:
我的 HTML 页面:
在页面的Header区域:
<script type="text/javascript">
function AddEmployee() {
jQuery.support.cors = true;
var Product = {
Name: $('#txtTitle').val(),
Price: $('#txtPrice').val(),
Category: $('#txtGenre').val()
};
$.ajax({
url: 'http://localhost:62310/api/products',
type: 'POST',
data: JSON.stringify(employee),
contentType: "application/json;charset=utf-8",
success: function (data) {
WriteResponse(data);
},
error: function (x, y, z) {
alert(x + '\n' + y + '\n' + z);
}
});
}
</script>
点击 btnAdd 按钮
<asp:Button ID="btnAdd" runat="server" OnClick="AddEmployee()" Text="Add" />
但是当我运行 asp.net 项目时,它说 aspx 页面不包含“AddEmployee()”函数的定义。
请提出您的建议 提前致谢。 苏尼尔·贾达夫
【问题讨论】:
-
重要提示:页面上有一个按钮,其 onclick 事件已分配给 AddEmployee()。
-
你在哪里使用产品?为什么不使用 jQuery 添加 onclick?在 ASP 中可能不仅仅是 onclick
标签: javascript jquery asp.net-web-api