Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
104 views
in Technique[技术] by (71.8m points)

javascript - Alert function not working after ajax call in laravel

<script>
    $(function () {
        $("#portal_register_post").validate({
            rules: {
                user_email: {
                    required:true,
                    email: true,
                    maxlength: 50
                },
                CreatePwd: {
                    required:true,
                    maxlength: 50,
                    minlength: 8,
                    pwcheck:true
                },
                confirmpassword: {
                    required:true,
                    equalTo: "#CreatePwd"
                }
            },
            messages: {
                user_email: {
                    required: "Please Enter E-mail",
                },
                CreatePwd: {
                    required: "Please Enter Password",
                },
                confirmpassword: {
                    required: "Please Enter Confirm Password",
                }
            },
            submitHandler: function(form) {
                var $form_id = '#register_post';
                var form = document.forms.namedItem("register_post");
                var formdata = new FormData(form);
                var $inputs = $($form_id+' :input:not(input[name=_token] :input)');
                $inputs.prop("disabled", true);

                request = $.ajax({
                    async: true,
                    type: "POST",
                    dataType: "json",
                    contentType: false,
                    url: "{{ URL::to('/portal/register') }}",
                    data: formdata,
                    processData: false,
                    success: function (result) {
                        alert(result);
                    },
                    timeout: 1000000
                });
                request.always(function () {
                    $inputs.prop("disabled", false);
                });
            }
        });
    });
</script>

route:

Route::get('/portal/register', 'PortalController@register');
Route::post('/portal/register', ['as' => 'portal.register.post', 'uses' => 'PortalController@postRegister']);

In the above code I am simply want to get response in my alert function after ajax success but what happen when I click on form submit button then it show status code: 302 and not able to get response in alert function. I don't know where I am doing wrong? Please help me to solve this.

Thank you

question from:https://stackoverflow.com/questions/66058390/alert-function-not-working-after-ajax-call-in-laravel

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...