lundi 29 novembre 2021

AJAX json response data undefined in Laravel 5.7

I have to get response data from API I have succeeded in response but when I am getting one response of data then I have got an undefined error. I am trying to get an error message from API on button click event or display the alert message of API error response of data.

Controller :

 public function apiStatus(Request $request)
{

    $to =  $this->shop->api_test_phone;

    $curl = curl_init();
    $response = my_api;

    curl_setopt($curl, CURLOPT_URL, $response);
    curl_exec($curl);

    $response = json_encode($response);
    curl_close($curl);
    return $response;
}

Blade file:

<script type="text/javascript">
$(document).on('click','#checkApi',function(){
    startAjaxLoading();
    $.ajax({
            type: "GET",
            cache: false,
            url: "",
            success: function (response) 
            {
                console.log(response);
            
                if (response == true) 
                { 
                    var msg = response.message;
                    console.log(msg);
                    notie.alert({text: msg });
                    stopAjaxLoading();
                }
                else
                {
                    var msg = response.message;
                    console.log(msg);
                    notie.alert({ text: msg });
                    stopAjaxLoading();
                }
            }     
        });
    });


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire