1
Hello, I’m getting to know this framework now. I’m trying to send ajax via post and see if it returns something, but it didn’t work, follow the problem below:
$("#modal-comentario").on("click", function(){
var get_id = $(this).data("obs-id");
$.ajax({
headers: {
'X-CSRF-Token': $('input[name="_token"]').val()
},
url: "{{ URL::to('lista-contatos/update') }}",
type: "POST",
dataType: 'json',
data: {
"id": get_id
},
success: function(result){
alert(result);
}
});
});
Contactocontroller
public function update(Request $request){
echo "teste";
}
Route
Route::post('/lista-contatos/update',
['as' => 'lista-contatos',
'uses' => 'ContatoController@update']);
Is not generating the alert(result)
when I click the button.
I’ve made these modifications, and it’s still not coming up. I did a test here changing the post route to get and I downloaded the url to see if the string is being printed and it was printable. Weird.
– denali
@There may be several things, Route equals, it may be wrong setting. If you have debugged the browser, press F12 on the console and run it to give you an idea. Another thing after this line
var get_id = $(this).data("obs-id");
give a console.log(get_id). has several problems in your code one of these may contain problems!– novic
@I’ve made a functional, simple example that will help you with your solution. It’s very similar, I hope you make the most of it. If you can take this code and click on a separate controller for testing.
– novic