2011-01-09 61 views
0

所以基本上,我有一个像下面这样的小插件,它做的是提交表单与jquery方法post。通过服务器响应回调函数在jquery插件

(function($){ 
$.fn.ajaxSubmit = function(options){ 
    var defaults = { 
    url:'', 
    success:function(){}, 
    error:function(){} 
    }, 
    o = $.extend({},defaults, options); 
    return this.each(function(){ 
    var $this=$(this); 
    $this.submit(function(e){ 
    $.post(o.url,$this.serialize() , 
    function(response){ 
    if(response.status == 'success'){ 
     o.success.call(this); 
    } 
    else if(response.status == 'error'){ 
     o.error.call(this); 
    } 
    },'json'); 
    return false; 
    }); 
    }); 
} 
})(jQuery); 

这是它怎么叫

$('#form').ajaxSubmit({ 
    url:'www.myownwebsite.com/play/processform', 
    success:function(response){alert(response.status)}, 
    error:function(response){alert(response.status);} 
}); 

的问题是,在执行脚本的时候,我得到的错误“的回应是不确定的”。很明显,我知道最新的错误,但我该如何正确地做到这一点?

+0

求你了......我的眼睛......用空格... – 2011-01-09 18:19:02

回答

1

你试过o.success.call(this,response);

+0

哇,很容易比我想象的,谢谢 – 2011-01-10 03:45:01