I'm doing a test using Laravel, jQuery and PHP.
I have routes, action in jQuery, methods in controllers and two views-blade, one to provide search elements (BillingListView.blade.php) and another to display the result (BillingApplication.blade.php).
The project is simple: I have a list of records coming from a database, which are loaded into a view-blade table. Next to each row of this table, a 'hot' button is created for each record received. When you click any of these buttons, a jQuery click action associated with the pressed button triggers a PHP method that returns a record from another table. This record is passed to a Laravel / PHP statement that opens another view-blade to display the values of the found record.
The initial 'route', which opens the view with the records, is:
Route::get("/pesquisar-Faturamento-verificarCobranca",
"FaturamentoController@verificarCobranca");
The fraction of the 'view' code, called by the 'route' above, which in the opening event loads database records, is:
@foreach($pendencias as $p)
<tr>
<td>
<button class="claBtnFaturamentoAbrir" title="{{$p->identificador}}">Abrir este</button>
</td>
<td>
{{$p->siglaaprovador}}
</td>
<td>
{{$p->siglaredator}}
</td>
<td>
{{$p->vencimento}}
</td>
<td>
{{$p->cobrado}}
</td>
</tr>
@endforeach
Click the
<button class="claBtnFaturamentoAbrir" title="{{$p->identificador}}">Abrir este</button>
causes an event in jQuery, which is
jQuery(".claBtnFaturamentoAbrir").on("click",function(){
var identificador=jQuery(this).prop("title");
jQuery.get("pesquisar-Faturamento-verFormulario",{identificador:identificador},function(){
});//get
});//idBtnFaturamentoAbrir on click
The jQuery method, using the .get method and the {identifier: identifier} parameter, causes another route to be triggered by a method in its controller:
Route::get("/pesquisar-Faturamento-verFormulario", "FaturamentoController@verFormulario");
The method in the controller has the following code fragment:
public function verFormulario(){
$identificador=$_GET['identificador'];
$resultado=DB::select('instrução SQL omitida para maior clareza');
return view('FaturamentoAprovarView')->with("fatura",$resultado);
}
The last statement, then, as shown above is
return view('FaturamentoAprovarView')->with("fatura",$resultado);
But this is not what happens. The 'view' 'BillingAuthorizeView' is not called; she does not open. The screen remains on the first screen, the one the initial 'route' called. Permanence, however, is illusory, because in fact the initial view is reloaded, rather than overwritten by the controller call.
Searching the developer area, in the Chrome log, it is confirmed that the method is called, but the other route, the initial one, is the one that prevails because it is the last one:
jquery.js:4 XHR finished loading: GET "http://172.16.0.30/laravel/tempo/public/pesquisar-Faturamento-verFormulario?
identificador=29638_1472048778961_121
Navigated to http://172.16.0.30/laravel/tempo/public/pesquisar-Faturamento-verificarCobranca?
redator_tabusuarios=fulano de tal
What I want is for the code to stop at the first line of the above log.