Can anyone help me with this code? Because it does not work? I'm trying to send a value received by a form to a php file, use that value in my SQL query by searching for records that contain that value, return a Json array with the result (s) and print them on the screen using html .
My Query SELECT:
$sql= "SELECT * FROM incidente WHERE (titulo LIKE '%':buscar'%' OR descricao LIKE '%':buscar'%')";
//...
$recebeConexao->bindParam(':buscar', $_POST['busca'], PDO::PARAM_STR);
HTML code:
<!-- here I am creating a form whit text input and a button that call the function enviar() -->
<form id="buscar">
<input id="busca" name="busca" type="text" placeholder="Buscar incidente" />
<input onclick="enviar()" type="button" value="ok" />
</form>
<!-- creating a array that will receive values from SQL consult -->
<div id="content" class="content">
<article class="underline">\
<a href="incidente.html"><img id="incidente"\
src="img/buraco.jpg" alt="Incidente" /></a>\
<h2><a href="basic_markup.html" id="tit">'+tit+'</a></h2>\
<p id="desc">'+desc+'</p>\
<div class="date" id="date">'+dateVal+'</div>\
<img class="tick" alt="não resolvido" src="img/no-tick.png">\
<img class="apoio" alt="apoiar" src="img/apoio.png">\
</article>'
</div>
Send () function:
function enviar() {
function viewData(data, el) {
var content = '';
for (var i in data) {
var tit = data[i].titulo;
var desc = data[i].descricao;
var dateVal = data[i].data;
content += '<article class="underline">\
<a href="incidente.html"><img id="incidente"\
src="img/buraco.jpg" alt="Incidente" /></a>\
<h2><a href="basic_markup.html" id="tit">'+tit+'</a></h2>\
<p id="desc">'+desc+'</p>\
<div class="date" id="date">'+dateVal+'</div>\
<img class="tick" alt="não resolvido" src="img/no-tick.png">\
<img class="apoio" alt="apoiar" src="img/apoio.png">\
</article>';
}
$('#'+el).html(content);
}
$(function(){
$.ajax({
var formula = $('#buscar').serialize();
type: "POST",
data:formula,
url: "http:/ip/connect/www/buscar.php",
dataType: "json",
success: function (data) {
viewData(data,'content');
}
});
});
}
I'm getting the error: enviar is not defined
...