开发者

Is there any way to run first base function that defined in ajaxSetup?

$.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;
    }
开发者_StackOverflow});

$.ajax({
    success: function(newMsg){
        // call new functions of newMsg object
        newMsg.display();
    }
});


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜