You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Greg Huber <gr...@gmail.com> on 2017/02/13 10:06:33 UTC

Showcase app ajax validation check

Was looking at some client side validation, with the showcase app. I use
firefox and it was not working, it just returned Network or server error!

https://struts.apache.org/docs/ajax-validation.html

The ajax call was returning 400, so falls back onto the error function and
just displays the network error message.

Not sure the best way to make this cross-browser complaint, other than
adding a check?
..
error: function(xhr, textStatus, errorThrown) {
            if (restoreFunction) {
                restoreFunction();
            }
            // show user an error message
            if(xhr.status == 400) {
              _handleValidationResult(_form,
jQuery.parseJSON(xhr.responseText))
            } else {
              _handleValidationResult(_form, {errors: ['Network or server
error!']})
            }
        }
..

Re: Showcase app ajax validation check

Posted by Christoph Nenning <Ch...@lex-com.net>.
> >>I don't understand, 400 is a common way to say that the request was
> >>wrong, do you want something else?
> >
> > On firefox, a 400 triggers the
> >
> > error: function(xhr, textStatus, errorThrown) {..}
> >
> > so only displays 'Network or server error!' rather than the validation
> > response.
> >
> > Maybe a 400 on other browsers triggers the success: function rather 
than
> > the error:  ???
> >
> > success: function (response, statusText, xhr) {..}
> 
> I think it will always trigger an error function, only 200 will
> trigger a success function. I think the example is very simple and you
> should extend it, like checking if it was 400 or 500
> 
> 

I'm quite sure that it was working when I created this. I get the same 
wrong behavior in chrome and IE, too. My guess is that struts was changed 
to use status code 400 when validation errors are present. Previously it 
must have used status code 200.

I've pushed a change based on Greg's sample and put it in wiki:

https://cwiki.apache.org/confluence/display/WW/AJAX+Validation


Actually the success function makes no sense in this new situation anymore 
but for now I've left it.


Regards,
Christoph

This Email was scanned by Sophos Anti Virus

Re: Showcase app ajax validation check

Posted by Lukasz Lenart <lu...@apache.org>.
2017-02-16 9:08 GMT+01:00 Greg Huber <gr...@gmail.com>:
>>I don't understand, 400 is a common way to say that the request was
>>wrong, do you want something else?
>
> On firefox, a 400 triggers the
>
> error: function(xhr, textStatus, errorThrown) {..}
>
> so only displays 'Network or server error!' rather than the validation
> response.
>
> Maybe a 400 on other browsers triggers the success: function rather than
> the error:  ???
>
> success: function (response, statusText, xhr) {..}

I think it will always trigger an error function, only 200 will
trigger a success function. I think the example is very simple and you
should extend it, like checking if it was 400 or 500


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Showcase app ajax validation check

Posted by Greg Huber <gr...@gmail.com>.
>I don't understand, 400 is a common way to say that the request was
>wrong, do you want something else?

On firefox, a 400 triggers the

error: function(xhr, textStatus, errorThrown) {..}

so only displays 'Network or server error!' rather than the validation
response.

Maybe a 400 on other browsers triggers the success: function rather than
the error:  ???

success: function (response, statusText, xhr) {..}




On 15 February 2017 at 19:32, Lukasz Lenart <lu...@apache.org> wrote:

> 2017-02-13 11:06 GMT+01:00 Greg Huber <gr...@gmail.com>:
> > Was looking at some client side validation, with the showcase app. I use
> > firefox and it was not working, it just returned Network or server error!
> >
> > https://struts.apache.org/docs/ajax-validation.html
> >
> > The ajax call was returning 400, so falls back onto the error function
> and
> > just displays the network error message.
> >
> > Not sure the best way to make this cross-browser complaint, other than
> > adding a check?
> > ..
> > error: function(xhr, textStatus, errorThrown) {
> >             if (restoreFunction) {
> >                 restoreFunction();
> >             }
> >             // show user an error message
> >             if(xhr.status == 400) {
> >               _handleValidationResult(_form,
> > jQuery.parseJSON(xhr.responseText))
> >             } else {
> >               _handleValidationResult(_form, {errors: ['Network or server
> > error!']})
> >             }
> >         }
> > ..
>
> I don't understand, 400 is a common way to say that the request was
> wrong, do you want something else?
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>

Re: Showcase app ajax validation check

Posted by Lukasz Lenart <lu...@apache.org>.
2017-02-13 11:06 GMT+01:00 Greg Huber <gr...@gmail.com>:
> Was looking at some client side validation, with the showcase app. I use
> firefox and it was not working, it just returned Network or server error!
>
> https://struts.apache.org/docs/ajax-validation.html
>
> The ajax call was returning 400, so falls back onto the error function and
> just displays the network error message.
>
> Not sure the best way to make this cross-browser complaint, other than
> adding a check?
> ..
> error: function(xhr, textStatus, errorThrown) {
>             if (restoreFunction) {
>                 restoreFunction();
>             }
>             // show user an error message
>             if(xhr.status == 400) {
>               _handleValidationResult(_form,
> jQuery.parseJSON(xhr.responseText))
>             } else {
>               _handleValidationResult(_form, {errors: ['Network or server
> error!']})
>             }
>         }
> ..

I don't understand, 400 is a common way to say that the request was
wrong, do you want something else?


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org