0

So basically, I have a small plugin like below, what it does is submit the form with jquery method post.

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

This is how its called

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

The problem is, when the script is executed, I get the error "response is undefined". Clearly I know whats wrong, but how can I do it properly?

1
  • Please... my eyes... use whitespace... Commented Jan 9, 2011 at 18:19

1 Answer 1

1

have you tried o.success.call(this,response);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.