简体   繁体   中英

500 internal server error AJAX POST request laravel server

I am trying to make ajax post requests to the server so that i can get data to update my view

My Ajax code

$(document).ready(function() {
    $.ajax({
        async: true,
        method:'POST',
        url:'{{route('pusher')}}',
        headers: {
            "Content-Type": "application/json",
            'X-CSRF-Token': '{{ csrf_token() }}'
        },
        data:{
            mac:'{{$slaves['mac']}}'
        },
        success:function(response)
        {
            alert(response);
        },
        error:function(iqXHR,testStatus,errorThrown)
        {
            alert('error');
        }
    })
});

The API

public function getSlaveDataJson(Request $request)
{
    $temp = [
        'action'=>'list_slave',
        'mac'=> $request->mac,
        'type' => 'all',
        'appkey' => '3E6157D4409B28627586E37F7B1E656E'
    ];

    json_encode($temp);

    $response = Curl::to('http://103.31.82.46/open/open.php')
    ->withContentType('application/json')
    ->withData($temp)
    ->asJson(true)
    ->withHeader('Postman-Token: d5988618-676e-430c-808e-7e2f6cec88fc')
    ->withHeader('cache-control: no-cache')
    ->post();

        self::destroy($request->mac);
        self::addAllSlaves($response);

    return $response;
}

The API returns json data back if i run it with postman but i get 500 internal server error when i run it from ajax. help.

PS will using websockets instead of this help me in creating an automatically updating table?

我通过使用Fetch API使其工作!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM