4
What I need
When the user clicks on the submit button the ajax will call a method of a class to check if the typed text already exists and in a table. It returns the result, if it is false it lets the form be sent and the field is registered in the bd, otherwise it will present an Alert with the typed text and that it already exists.
What I did
I created the form using Blade and did the type="button"
pure html for not finding in the Laravel documentation.
home.blade.php
{!! Form::open(array('action' => 'HomeController@gerarPdf','method' => 'POST')) !!}
{!! Form::text('numeroDocumento[]', null,array(
'placeholder' => 'Código da Entidade',
'maxlength' => '5',
'required' => ''
)); !!}
<input type="button" value="Gerar Código" name="submitBarcode" id="submitBarcode" required/>
{!! Form::close() !!}
Routes.php
Route::post('verificarBarcode', 'HomeController@verificarBarcode');
js
$('#submitBarcode').click(function () {
$.ajax({
type: 'post',
url : 'verificarBarcode',
cache: false,
dataType: 'json',
data: $('#formBarcodeId').serialize(),
success : function(msg){
if (msg.status == 0) {
alert("Tem Coisa Repetida");
}
else{
alert("Não Tem Coisa Repetida");
}
},
error:function (xhr, ajaxOptions, thrownError) {
alert(xhr.responseText);
}
});
});,
When I click on the send it gives this Alert with all the html code of the result. I copied the code to an empty page and it resulted me in this image. Because he is giving this problem with the token ?
Where does the
#formBarcodeId
?– gmsantos