2011-01-09 3 views
0

Also im Grunde habe ich ein kleines Plugin wie unten, was es tut, ist das Formular mit jquery method post übergeben. Diesepass Serverantworten auf Callback-Funktion in jquery Plugin

(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); 

ist, wie seine

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

Das Problem ist, wenn das Skript ausgeführt wird, erhalte ich die Fehlermeldung „Antwort ist nicht definiert“. Klar weiß ich, was falsch ist, aber wie kann ich es richtig machen?

+0

Bitte ... meine Augen ... Verwendung Leerzeichen ... –

Antwort

1

haben Sie o.success.call(this,response); versucht

+0

wow, das ist einfach, als ich dachte, Dank –