I’ve created a plug-in that duck-punches the jQuery Ajax function. One problem that I cannot locate when running the Ajax unit tests for 1.4.2 It will not pass the two tests
- Ajax events with context
- jQuery.ajax context modification
Test one has a test that always fails:
function callback(msg){
return function(){
equals( this, context, "context is preserved on callback " + msg );
};
}
The this reference instead of being the <div/> tag becomes an XPC Cross Origin Wrapper.
My unit tests for the plug-in can be run here:
The failing unit tests can be run here:
One note is that jQuery 1.4.2 Ajax doe not handle a server response of 301 with FireFox 3.6.8. It will be returned as 0. I’ve modified my jQuery Library to account for this.
Also some JSONP stop watch timing. BUG #5383.
And maybe some presentation issues and this plug-in will be ready for the wild.
Any help would be appreciated. including design. Thanks in advance.
The problem is you’re losing context in your
service.monitormethods when calling the originally passedsuccess,error,beforeSendandcompletehandlers.Take a look in
ajaxMonitor.service.js, you need to replace each of the original handler invocations with a.call()to maintain the proper context:1) In service.monitorSuccess():
2) In service.monitorError():
3) In service.monitorBeforeSend():
4) In service.monitorComplete():
I copied your test setup here so you can see the results: http://ncraver.com/AjaxTest/
Notice some other tests are failing…these are unrelated to my changes, they’re the result of the my site not running PHP, so tests are getting an improper response from those
.phppages 🙂