I would like to pass to a jQuery function a regular function, instead of the usual anonymous function, but I'm not sure how such a thing could be done.
Instead of this:
function setVersion(feature) {
$.post("some.php", { abc:"abc" },
function(data){
// do something here
}, "json");
}
I would like to do this:
function foo(data){
// do something here
}
function setVersion(feature) {
$.post("some.php", { abc:"abc" }, foo, "json");
}
Thank you.
I would like to pass to a jQuery function a regular function, instead of the usual anonymous function, but I'm not sure how such a thing could be done.
Instead of this:
function setVersion(feature) {
$.post("some.php", { abc:"abc" },
function(data){
// do something here
}, "json");
}
I would like to do this:
function foo(data){
// do something here
}
function setVersion(feature) {
$.post("some.php", { abc:"abc" }, foo, "json");
}
Thank you.
Share Improve this question asked Apr 17, 2010 at 20:52 thedpthedp 8,50816 gold badges57 silver badges100 bronze badges 3 |3 Answers
Reset to default 12Yeah, already works. But you want it probably look like this:
function setVersion(feature, myFunction) {
$.post("some.php", { abc:"abc" }, myFunction, "json");
}
setVersion(blah, foo);
Should run just fine.
I believe jQuery is actually meant to use the regular function, called by name. Using the anonymous function is simply a replacement for a named function that would otherwise be passed.
Yes, that is exactly how you do it.
"foo"
, didn't bother to run it as justfoo
... And then I forgot the "" in the question :) I need to get some sleep!!! – thedp Commented Apr 17, 2010 at 20:59