galera eu tenho esses 2 inputs no formulário e preciso fazer uma requisição via get com ajax. como faço?
<input id="nome" name="nome" placeholder="" class="form-control input-md" maxlength="200" required="" type="text">´
<input id="cnpj" name="cnpj" class="form-control" type="text" maxlength="18" onKeyPress="MascaraCNPJ(form1.cnpj);"
maxlength="18">
$(document).ready(function() {
$('#cadastrar').click(function()
{
$.ajax({
type: "GET",
url: "http://localhost:8033/minhaapi"
dataType: 'json'
})
.done(function(data) {
if(data.error){
alert(data.message);
}
});
})
});
Faz tempo que não vejo ajax, mas eu fazia da seguinte forma:
function consultar() {
$.ajax({
url: "http://localhost:8033/minhaapi",
type: "get",
success: function(response) {
console.log(response);
}
});
}
não entendi muito bem…
onde eu estou pegando os dados digitados no input?
gbuenoo
#4
@cleitonti, no caso de uma requisição do tipo Get, vc passa os parâmetros pela URL. Você poderia fazer algo como:
var myUrl = "http://localhost:8033/minhaapi?nome=" + $("#nome").val() + "&cnpj=" $("#cnpj").val();
function consultar() {
$.ajax({
url: myUrl,
type: "get",
success: function(response) {
console.log(response);
}
});
}
1 curtida