我对jquery不太好,也许这个标题不能很好地解释我想做什么但是这里有:
$.ajax({
url: 'my_action',
dataType: 'script',
beforeSend: function() { //can i not just call a script here instead?
if (1 == 1) //just an example
{
return false
}
},
complete: function() {
console.log('DONE');
}
});?
Run Code Online (Sandbox Code Playgroud)
所以beforeSend,我想调用脚本而不是内联函数.这是因为我的功能很长,它使我看起来麻烦的ajax代码.
那可能吗?
$.ajax({
url : 'my_action',
dataType: 'script',
beforeSend : foo // where foo is a function name.
Run Code Online (Sandbox Code Playgroud)
〔实施例:
function foo(){
// Do your magic here.
}
Run Code Online (Sandbox Code Playgroud)