0
Good night! I am trying to consume an API using Jquery and Laravel. I created the route to access and save the data, access always returns me with status 0.
web php.:
Route::any('http://moviecom.com.br/MoviecomAPI/','MoviecomController@store')->name('movieAPI');
In the view I put the javascript code:
$.ajax({
                headers: {
                    'user_token': '',
                },
                type: 'GET',
                dataType: "json",
                url: "{{!! URL::to('http://moviecom.com.br/MoviecomAPI/') !!}}",
                data: {
                    'praca': 'JU2',
                    'data_ini': '2018-05-10',
                    'data_fim': '2018-05-20'
                },
                success: function(response) {
                    console.log(response);
                    if(response.status == "Success") {
                        $(response.data[0].filmes).each( function(i, el) {
                            // Pegar os dados e salvar no banco
                        })
                    }
                    else {
                        console.log(response.data[0]);
                    }   
                }
I am using the token correctly and the api documentation says nothing about.
Try to add in the AJAX request
contentType: "application/json"to indicate that the data being sent to the server is of the JSON type and use the functiondata: JSON.stringify(seusDados)to convert the data to a JSON string.– Wesley Gonçalves
Correction : use
contentType: "application/json"to indicate that the data being received by the server response are of type JSON.– Wesley Gonçalves
I tried to add the contenttype, but still keeps returning me this answer: [Object Object]{readyState: 0, responseJSON: Undefined, status: 0, statusText: "Error: Aces..."}
– Igor Faria
What is the documentation link for this Api? Your route is wrong too is not how you do it ... !!!
– novic
@Virgilionovic the documentation is http://moviecom.com.br/MoviecomAPI/documentation/ I am trying some other possible solutions as well, but without success.
– Igor Faria
Where you created your token?
– novic
@Virgilionovic the token sent me and I have tested in code without the Aravel, rotate the data according to the documentation, but with the Laravel does not work. Returning only status: 0
– Igor Faria
Because the Laravel was done wrong.
– novic