0
I’m doing a test using Laravel, jQuery and PHP.
I have routes, jQuery action, controller methods, and two views-Lade, one to provide search elements (Invoicingview.blade.php) and one to display the result (Invoicing approvview.blade.php).
The project is simple: I have a list of records coming from a database, which are loaded into a view-Lade table. Next to each row of this table, a 'hot' button is created for each received record. When you click any of these buttons, a jQuery 'click' action, associated with the button pressed, triggers a PHP method that returns a record from another table. This record is passed to an Laravel/PHP statement that opens another 'view-Blade' in order to display the values of the record found.
The initial route, which opens the view with the records is:
Route::get("/pesquisar-Faturamento-verificarCobranca",
"FaturamentoController@verificarCobranca");
The 'view' code frame, called by the 'route' above, which in the opening event loads records from the database, 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
The click on the button
<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, through the method. get and from the parameter {identifier:identifier}, causes another route which, in turn, will trigger a method in the respective 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 instruction, then, as shown above is
return view('FaturamentoAprovarView')->with("fatura",$resultado);
But this is not what happens. The 'view' 'Invoicingapprovview' is not called; it does not open. The screen remains on the first screen, the one that the initial route called. The permanence, however, is illusory, because in fact the initial 'view' is reloaded, rather than being overwritten by the call in the 'controller'.
Searching the programmer area, in the Chrome log, it is confirmed that the method is called, but the other route, the initial, is prevailing, for being the last:
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 wish is that the code stops at the first line of the log above.
Lucas, it partially solves me, but I had trouble elsewhere. I decided to modify the route to Route::get("/search-Billing-verFormulario/{identifier}", ['as' => "open Trial", 'uses' => "Invoicing Controller@verformulario"]); and Blade to <a href="{{ route('open Trial', $p->identifier ) }}">Click here</a>
– user4701