我有函数tryGetTicket必须在我的loginUrl调用 ajax 请求。但是当我调用这个函数时,它会忽略我的 ULR 并在没有loginUrl的情况下发送 get 请求,即我希望什么请求会在http://example.com/sys/login但实际上是http://example.com发送。怎么了?
$(function(){
var tryGetTicket =
function (loginUrl, param)
{
var ticket = null;
$.ajax({
url: loginUrl,
dataType: "json",
data: param,
success: function( response ) {
var result = null;
//do something
ticket = result;
}
});
return ticket;
}
$("#importDialog").click (function(event) {
event.preventDefault();
var alfTicket = getCookie("alf_ticket");
var ticket = tryGetTicket("/sys/login", $.param({"alf_ticket" : alfTicket}));
///...
}
});
答: 它工作正常。感谢您的建议。
$(function(){
var tryGetTicket =
function (loginUrl, param, callback)
{
var ticket = null;
$.ajax({
url: loginUrl,
dataType: "json",
data: param,
success: function( response ) {
var result = null;
//do something
ticket = result;
callback(ticket);
}
});
}
$("#importDialog").click (function(event) {
event.preventDefault();
var alfTicket = getCookie("alf_ticket");
var ticket =
tryGetTicket("/sys/login",
$.param({"alf_ticket" : alfTicket}),
function(){
///...
});
}
});