Good afternoon. I have a problem with my php code developed in Laravel 4. I have a function in JavaScript that performs an action using $ .post and on success, calls another Javascript function, this second using $ .ajax. The two in .blade pages. The problem is that when entering the second function, I suspect that the route passed in the url field is not found, but I can not find the error. Can someone help me? Here are the codes:
Javascript functions:
function form_variations_submit()
{
$.post(
'{{route('admin.ajax.save')}}',
$('#form').serialize(),
function(data) {
if(data.sucesso) {
alert("Alterações Salvas! "+data.pvid);
var pvid = data.pvid;
alert("pvid = "+pvid);
var flagOrder = envia_pvid(pvid);
alert("FlagOrder = "+flagOrder);
} else {
alert(data.erro);
}
}
);
return false;
}
function envia_pvid(id){
var pId = id;
alert("Entrou na 2 função! Envia_id "+ pId);
$.ajax({
type: 'POST',
url: '{{route('admin.ordem')}}',
data: { pId : pId
},
sucess: function(data) {
if(data.pvid){
var ret = data.pvid;
alert(ret);
return ret;
} else{
alert("ERRO!");
}
},
dataType: "json"
});
}
Route:
Route::post('p_var', array('as' => 'admin.ordem', 'uses' => 'Admin_Controller@setaOrdem'));
Function OrderOrder in Controller:
public function setaOrdem()
{
$pvid = Input::get('pId');
return Response::json(array('sucesso' => true,'pvid' => $pvid));
}
Alerts are run nominally until the FlagOrder alert returns "undefined".