CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ruby & Ruby On Rails (http://www.codingforums.com/forumdisplay.php?f=44)
-   -   Validation messages and $.parseJSON(xhr.responseText).errors (http://www.codingforums.com/showthread.php?t=280039)

akvarel 10-29-2012 09:06 PM

Validation messages and $.parseJSON(xhr.responseText).errors
 
Hello!
I try to catch a validation message with a
Code:

`$.parseJSON(xhr.responseText).errors`
but an allert message hows me "undefined" and I dont understand why.

hier are my validations:


Code:

validates :upload_file_name,  :presence  => true,
                                    :format    =>{:with => %r{\.(jpg)$}i,:message =>"It should be a pdf File"}
                                   
      validates_uniqueness_of :upload_file_name, :message => "blabla"
   
      validates :upload_file_size,  :inclusion  => {:in =>1.megabytes..20.megabytes,:message=>"bla"}

json:


Code:

format.json{ render json: {error: @upload.errors.full_messages}, :status =>422}
and javascript for that:

Code:

$('#fileupload').fileupload({     
   
   
            error: function(xhr){
              var errors = $.parseJSON(xhr.responseText).errors
              alert(errors)       
            }
                  });

Thanks in advanced


All times are GMT +1. The time now is 06:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.