Can we add additional methods to jqXHR object?
I had a app built using prototype.js which was extending the response
Ajax.Response.addMethods({});
What is the equivalent for Jquery?
I want to add few methods that are specific to my app.
For example, I want to add a method
getMyHeader: function(name)
{
return this.getResponseHeader('MY-'+name);
}
which returns me a specific header sent by server.
It doesn’t look like jQuery specifically supports this. The jqXHR object they create is just a generic object with methods added as properties so there isn’t a prototype you can modify and I don’t see any jQuery methods for modifying it.
The only work-around I could see was to register a handler for a global ajax event like
jQuery.ajaxSend()and add the desired methods to each specific jqXHR object in that global handler. Then, those methods would be available later.