The JS below captures the value of the URL and assigns it to value
of input
.
var valor_num = /num_nfe=([^&]+)/.exec(window.location.href)[1];
//console.debug("Num. NFe: "+$("[name='num-nfe']").val());
//console.debug("Form: "+ JSON.stringify($('#meu_form').serializeObject()));
$.post("actions/autosalvar.php", function (data) {
$("[name='cliente']").attr('value', data.cliente);
$("[name='id-cliente']").attr('value', data.id_cliente);
$("[name='tipo-pessoa']").attr('value', data.tipo_pessoa);
$("[name='num-nfe']").attr('value', valor_num);
}, "json");
setInterval(function () {
var dados = $('#meu_form').serializeObject();
$.post("actions/autosalvar.php",
{'meus_dados': dados}).done(function( data ){});
}, 2000);
Initially, when attempting to capture this value on page autosalvar.php
, it is not set, and is only available in a second run.
1st page execution autosalvar.php
Array
(
[cliente] => João
[id-cliente] => 2
[tipo-pessoa] => PF
)
2nd run [after 2 second interval] of page autosalvar.php
Array
(
[cliente] => João
[id-cliente] => 2
[tipo-pessoa] => PF
[num-nfe] => 59
)