Is it possible to pass a function to the url field in an ajax call?
Is it possible to pass a function to the url field in an ajax call? I want to dynamically pass a different url to the ajax call mad开发者_Python百科e.
function getMeURL(){}
$.ajax({
url: getMeURL,
context: document.body,
success: function(){
$(this).addClass("done");
}
});
You shouldn't pass a function, but you can certainly pass the return value of a function.
url: GetMeUrl(args)
You can pass the result of a function, but not a function itself as you seem to be trying to do. Here's an updated example (notice the parentheses):
function getMeURL() {
return "http://www.example.com";
}
$.ajax({
url: getMeURL(),
context: document.body,
success: function(){
$(this).addClass("done");
}
});
use ()
function getMeURL(){}
$.ajax({
url: getMeURL(),
context: document.body,
success: function(){
$(this).addClass("done");
}
});
精彩评论