在我的 asp.net mvc4 项目中,我在Index.cshtml中有以下标记和 jquery -
<html>
<head>
<script src="~/js/jquery-2.0.3.min.js"></script>
<script type="text/javascript">
$(function () {
$('#btnLogin').click(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: '@Url.Content("../../WebService1.asmx/HelloWorld")',
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function () {
alert('success');
},
error: function () {
alert('error');
}
});
});
});
</script>
</head>
<body>
<form>
<button "btnLogin">Sign in</button>
</form>
但是ajax调用返回错误。有什么帮助吗?