2010-07-29 55 views
0
$.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(); 
    } 
}); 
+0

'success'(你想要的方式)

$.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(); } }); 

只消'函数( )'而不是像'success:function onSuccess(msg){...}'或者我错过了什么? – Reigel 2010-07-29 08:20:04

+0

成功需要'功能',我在ajaxSetup中给出了一个函数。这是工作。 – uzay95 2010-07-29 08:22:43

回答

0

这个怎么样?

$.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 
    } 
}); 

我在这里已经测试了jsfiddle

这里的另一种方式测试了这个here

+0

但味精没有改变(增加了新的功能等)。但这也看起来物品。 – uzay95 2010-07-29 08:27:32

+0

我已经按照你想要的方式更新了答案 – naikus 2010-07-29 08:34:11

+0

最后一个是完美的。非常感谢你... – uzay95 2010-07-29 08:41:31

相关问题