有没有办法运行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;
}
});
$.ajax({
success: function(newMsg){
// call new functions of newMsg object
newMsg.display();
}
});
答
这个怎么样?
$.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
'success'(你想要的方式)
只消'函数( )'而不是像'success:function onSuccess(msg){...}'或者我错过了什么? – Reigel 2010-07-29 08:20:04
成功需要'功能',我在ajaxSetup中给出了一个函数。这是工作。 – uzay95 2010-07-29 08:22:43