$.ajaxSetup({
success: function onSuccess(msg) {
// add some functions to `msg`
// then return to success method that defined in $.ajax
msg.display = function(){
alert(msg.M_Prop);
}
return msg;
}
});
$.ajax({
success: function(newMsg){
// call new functions of newMsg object
newMsg.display();
}
});
views:
18answers:
1
A:
How about this?
$.ajaxSetup({
url: "http://jsfiddle.net",
global: false,
type: "GET",
display: function(msg) { // custom display function defined in ajax setup
alert(msg);
}
});
$.ajax({
success: function(newMsg){
this.display("Hello: " + newMsg); //call it in your success handler
}
});
I've tested it here on jsfiddle
Here's another way (the way you want it)
$.ajaxSetup({
url: "http://jsfiddle.net",
global: false,
type: "GET",
success: function(msg) {
msg = msg || {};
msg.display = function() {
alert("display");
}
if(typeof(this.customSuccess) === "function") {
this.customSuccess(msg); // call the custom success function
}
}
});
$.ajax({
customSuccess: function(newMsg){ // define custom success function
newMsg.display();
}
});
Tested this here
naikus
2010-07-29 08:23:33
But msg didn't change(added new functions etc.) . But this also looks goods.
uzay95
2010-07-29 08:27:32
I've update the answer the way you probably want
naikus
2010-07-29 08:34:11
@naikus - last one is perfect. Thank you very very much...
uzay95
2010-07-29 08:41:31
@uzay95 You are welcome
naikus
2010-07-29 08:44:59