5
I am recording an address in the bank and with ajax I search it for display to the user. Provisionally, I am recording it in the input below:
<tr>
<td>Download:</td>
<td><input type="text" name="anexo" id = "anexo" size="60"></td>
</tr>
Ajax returns the correct value of the database, with HTTP and all:
http://pcn-sig.peccin.local/sig/subsistemas/projeto_testes/projetos/BASE/11.docx
My question is: How could this become a hyperlink or download button? I tested button, onclick, but he couldn’t recognize the link. Thank you
UPDATE
The Ajax that loads the data is this:
// Verifica se foi concluído com sucesso e a conexão fechada (readyState=4)
if (xmlreq.readyState == 4) {
// Verifica se o arquivo foi encontrado com sucesso
if (xmlreq.status == 200) {
//Se o retorno foi vazio do Oracle
if (xmlreq.responseText == "") {
document.getElementById("projeto").focus();
alert("Não existe o projeto informado!");
ids.forEach(function (id) {
document.getElementById(id).value = '';
document.getElementById("projeto").value = '';
});
//Se encontrou dados
} else {
//Aqui recebe os dados do processa.php, abre e aplica nos campos desejados
var dados = JSON.parse(xmlreq.responseText);
// função para preencher os campos com os dados
ids.forEach(function (id) {
document.getElementById(id).value = dados[id];
});
}
} else {
result.innerHTML = "Erro: " + xmlreq.statusText;
}
}
UPDATE 2
Below I was able to open a new window by clicking, but instead of passing the url it passes this.value
<td>Download:</td>
<td><input type="text" name="anexo" id = "anexo" onclick="location.href='this.value';" /></td>
Tried to insert the url into a
hyperlink
using the tag<a>
?– Pedro Camara Junior
I don’t know how to do this, because Ajax feeds the field by its id, on the page the value appears correctly, but as text only.
– Diego
You are using jQuery or some other framework or pure Javascript?
– Pedro Camara Junior
I am using pure JS. I tried the answer below but gave Ajax error...
– Diego