Firstly, here's my example code:
$.post( "test.php", { testdata : "signal" },
function( data ) { alert( "Nested function" )})
.done( function () { alert( "Done function" )});
I'm trying to get .done
to accomplish some stuff for me, it doesn't matter what. It won't fire, regardless of whether or not I nest a function directly in the $.post
parameters. Checking the console on Chrome shows that it's throwing an error of Uncaught TypeError: undefined is not a function
Playing around with lines and the error report shows me that it's definitely the .done
that's throwing the error, and that simply moving the .done
to directly after $.post
's close paren isn't effective.
There is another similar question that I saw, but it was for $.ajax, and I've attempted to implement the chaining they suggest, as above, to no effect. What am I missing?
EDIT: jQuery version is 1.4.4, the .post successfully returns data, and .always also fails.
Use .complete
instead:
$.post("test.php", { testdata : "signal" }, function () {
alert("Nested function"); })
.complete(function () { alert("Done function"); });
So, after investigation, and thanks to the comments of Jonathan Lonowski, algorhythm and War10ck, I've discovered the solution.
The version of jQuery I was running, 1.4.4, does not support the .done, .fail, .always, or .complete* methods. To fire an event after a success, I need to follow the inline format of:
$.post( url [, data ] [, success ] [, dataType ] )
...inserting the function that would normally go into .done
, after the url. This is what I was doing with the nested function in my original example, just requiring me to remove the .done function.
Thanks all.
* .complete is also deprecated in more recent builds of jQuery. Don't ever use it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.