아약스 메소드를 몇 군데 호출해야합니다. 따라서 별도의 메소드를 작성하여 코드를 최소화하려고합니다. 직접 사용하면 완벽하게 작동합니다. 하지만 분리하면 작동하지 않습니다.자바 스크립트에서 메소드를 호출하지만 오류가 발생합니다.
data: columns[5],
type: 'autocomplete',
options: { items: 100 },
source: function (query, process) {
$.ajax({
url: "/EditInitiatives.svc/GetLocationData?clientId=" + $value.val(),
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: {
query: query
},
success: function (response) {
process(response.d);
}
});
},
strict: true
}
이렇게 호출하면 작동하지 않습니다. 그것은 Microsoft JScript runtime error: 'query' is undefined
, 어떻게 고칠 말합니다?
{
data: columns[4],
type: 'autocomplete',
options: { items: 100 },
source: callAutoCompleteAjaxMethod(query, process, "/EditInitiatives.svc/GetLocationData?clientId=" + $value.val()),
strict: true
},
callAutoCompleteAjaxMethod = function (query, process, url) {
$.ajax({
url:url,
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: {
query: query
},
success: function (response) {
process(response.d);
}
});
},
오류의 어느 부분을 이해하지 못합니까? – SLaks