按下按钮时触发AJAX调用。当我使用error: function (response) {...}
时它可以工作,但当我尝试使用我之前定义的函数时
error: AjaxCallFailed(response)
它没有。
是否可以定义自己的功能,或者我必须使用匿名功能?这对我的剧本清晰非常重要。
<script type="text/javascript">
$(document).ready(function () {
function AjaxCallFailed(r) {
alert('failed:' + r.status + ':' + r.responseText);
};
$("#btnPickADate").click(function () { CallForTemplate(2); });
function CallForTemplate(tid) {
$.ajax({
contentType: "application/json; charset=utf-8",
type: "POST",
url: "../WebService/MyService.asmx/GetTemplates",
data: JSON.stringify({ 'myId': tid }),
dataType: "json",
success: function (response) {
...
}
},
//error: AjaxCallFailed(response) <-- This does not work.
error: function (response) {
alert('failed:' + response.status + ':' + response.responseText);
}
});
};
});
</script>
浏览器控制台出错
ReferenceError:未定义响应
CallForTemplate
jQuery.Callbacks / fire
jQuery.Callbacks / self.fireWith
.ready
完成