0
I have the following function in jquery which gives the delete in the record. It even deletes the record but does not go to the success, he goes to the error. Why will it be?
function deletar_cliente(id_cliente)
{
var mensagem_sucesso = "";
var mensagem_erro = "";
var url_cliente = "cadastro_clientes.php";
$.ajax({
url: url_base + "clientes/" + id_cliente,
type: 'DELETE',
dataType: 'json',
}).success(function(data)
{
console.log(data);
}).error(function(data)
{
console.log('erro');
});
}
CONTROLLER CUSTOMERS:
public function destroy($id)
{
$clientes = Clientes::find($id);
if(!$clientes) {
return response()->json([
'message' => 'Cliente não encontrado',
], 404);
}
$clientes->delete();
}
ROUTES:
use Illuminate\Http\Request;
Route::get('/', function () {
return response()->json(['message' => 'Rep Api', 'status' => 'Connected']);;
});
Route::resource('clientes', 'ClientesController');
Route::resource('fornecedores', 'FornecedoresController');
Route::resource('usuarios', 'UsuariosController');
Route::resource('estados', 'EstadosController');
Route::resource('municipios', 'MunicipiosController');
Route::post('autenticacao', 'AuthController@authenticate');
Route::get('get-municipios/{estados_id}', 'MunicipiosController@getMunicipios');
cadastro_clientes.phpreturns what a json? like it is? tried to give aconsole.log(data)in.error()?– rray
It just doesn’t return anything to me. It already falls right into the error.
– Felipe Michael da Fonseca
He even deletes, because I see in DB he deletes. And in error it gives: {readyState: 4, getResponseHeader: ?, getAllResponseHeaders: ?, setRequestHeader: ?, overrideMimeType: ?, ... } abort : teis(a) Always : and then#Xa;complete : and then##Xa() done : ĩ() error : ľ() fail : , and#Xa;and#Xa;and#Xa;sponHeaders #############a;, #getResponseHeader&###Xa;####Xa;######Xa;, #######Xa;, (#####Xa;, ####Xa;, #########Xa;, #########Xa;, #Xa;, ###### pipe
– Felipe Michael da Fonseca
In the
cadastro_clientes.phpleave as last lineecho json_encode(array('teste'=> 'teste...'));and putsconsole.log(data)in theerror()– rray
Is this not some sort of Laravel configuration? Because I’m using this php Restfull api
– Felipe Michael da Fonseca
Which jQuery version is using?
– Silvio Andorinha
Instead of model::find(id) try $client =model::findOrFail(id) and then give a dd($client); and treat the return
– Marcos Xavier