1
I am trying to send data to my controller using AJAX but am getting the following error:
AJAX error: error : Not Found
What can I be doing to solve this problem?
follows the codes:
route:
Route::post('/update/{postdata}', 'ReportsController@updateReport');
controller:
public function updateReport()
{
dd('Chegou no controller');
}
Javascript:
<script>
function mudar(obj){
var selecionado = obj.checked;
if (selecionado) {
var id = '1';
$.ajax({
method: 'POST', // Type of response and matches what we said in the route
url: '/update', // This is the url we gave in the route
data: {"_token":"{{csrf_token()}}", 'id' : id}, // a JSON object to send back
success: function(response){ // What to do if we succeed
console.log(response);
},
error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail
console.log(JSON.stringify(jqXHR));
console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
}
});
alert('fechado');
} else {
alert('aberto');
}
}
</script>
The route needs a parameter
/update/{postdata}
in your ajax you’re only sendingupdate
.– Kayo Bruno