1
I need to send a json object with ajax to an external API but cannot include variables instead of static values
var numSGPE = document.getElementById('numSGPE').value
var setor = document.getElementById('setor').value
var subTipo = document.getElementById('subTipo').value
var tipo = document.getElementById('subTipo').value
$.ajax({
url : "http://localhost:8080/NumDocumentos",
method : "POST",
contentType : 'application/json',
dataType : 'json',
data : '{"especie":""+tipo+"", "gerencia":""+setor+"", "numSGPE":""+numSGPE+""}'
}).done(function(res) {
console.log(res)
})
If you change the variables (tipo
, setor
, numSGPE
) by static values works well, but that send the values as they are in these variables.
so I’m not using any Angular or React framework, it’s a simple html that has some inputs and a javascript that makes this request at the click of the button, hence these strig templates do not work
– MarceloCP
the
template strings
is Javascript :)– Lucas Bittencourt
I’m sorry I thought javascript vanilla didn’t recognize ${} this format. It worked great Thanks.
– MarceloCP