0

In my local project I'm trying to get response from the queries. Then I'm trying to show the notification messages via sweet alert, but I have some problems. When I try to get the response, it gets an array type mean normal text like the picture below,

response return

My code is below:

My settings blade.php

<script src="/js/jquery.validate.min.js"></script>
<script scr="/js/jquery.form.min.js"></script>
<script src="/js/messages_tr.min.js"></script>
<script src="/js/sweetalert2.min.js"></script>
<script>
    $(document).ready(function () {
        $('form').validate();
        $('form').ajaxForm({
            beforeSubmit : function(){
            },
            success:function (response) {
                    swal(
                        response.baslik,
                        response.icerik,
                        response.durum

                    )

            }
        });
    });
</script>

My controller.php

$ayarlar = ayarlar::where('id',1)->update($request->all());
if($ayarlar) {
return response(['baslik'=>'Başarılı','icerik'=>'Kayıt 
Başarılı','durum'=>'success']);
}else {
return response(['baslik'=>'Başarılı','icerik'=>'Kayıt 
Başarılı','durum'=>'error']);
}

1 Answer 1

1

try to fix; response type select json.

return response()->json(['baslik'=>'Başarılı','icerik'=>'Kayıt Başarılı','durum'=>'success']);

add datatype for ajax

$('form').ajaxForm({
    beforeSubmit : function(){},
    dataType : "json",
    success:function (response) {
        swal(
            response.baslik,
            response.icerik,
            response.durum
        );
    }
});

or change succes function

success:function (response) {
    response = JSON.parse(response);
    swal(
        response.baslik,
        response.icerik,
        response.durum
    );
}
Sign up to request clarification or add additional context in comments.

1 Comment

it will solve your problem. If the problem persists, you can send a private message in Turkish. @sadri

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.