我需要一个超链接来执行Ajax调用,并且完成后,请执行超链接的标准操作。
<a href="afterwards.html" target="_blank" onclick="return CallFirst();">Link</a>
JavaScript函数调用$.ajax()
,等待成功或失败,则返回true。
function CallFirst()
{
$deferred = $.ajax({
type: "POST",
url: url,
data: data
});
// **todo** WAIT until the Ajax call has responded.
// Return true, which makes the <a> tag do it's standard action
return true;
}
代码必须等待$.ajax
成功,然后从CallFirst()
返回true。
$deferred.when()
立即终止。怎么能等待?
可能重复(http://stackoverflow.com/questions/12500669/html-anchor-tag-redirect-link-after-ajax-request) – Liam