this input #search performs the search for the value in my database from my database I pull a line Like the Rows that I show in #resultado:
I want that when loading the page: I loaded the last 10 results created, I already ordered it in the Mysql with the ORDERBY conditions. Now, when I start the web it obviously does not show any results, since I do not execute the jquery that is activated when I click on the input submit. My problem is only in the JQUERY that I can not condition it: Run when loading the web and also perform the search when you get the value and click on submit.
I clarify that I am a Rookie in JQUERY, I have been in San Google for more than 6 hours, I would not have recourse to you if I had not looked for it or made an effort, thank you very much, I will be reading you.
* NOTESE THAT HAD ALREADY CONDITIONED IF IT WAS NULL # search preloaded the page, but did not perform the search.
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var consulta;
//hacemos focus al campo de búsqueda
$("#busqueda").focus();
//comprobamos si se pulsa una tecla
$("#buscar").click(function(e){
//obtenemos el texto introducido en el campo de búsqueda
$("#buscar").click(consulta = $("#busqueda").val());
//hace la búsqueda
$.ajax({
type: "POST",
url: "buscar.php",
data: "b="+consulta,
dataType: "html",
beforeSend: function(){
//imagen de carga
$("#resultado").html("<p align='center'><img src='ajax-loader.gif' /></p>");
},
error: function(){
alert("error petición ajax");
},
success: function(data){
$("#resultado").empty();
$("#resultado").append(data);
}
});
});
});
</script>
<input type="text" name="" id="busqueda" value="">
<input type="submit" name="" id="buscar">
<div id="resultado">
<div class="row">
<div class="cols">SUPUESTO ID 001</div>
<div class="cols">DESCRIPCION PRECARGADO IMAGINARIAMENTE 001</div>
<div class="cols">PRECIO PRECARGADO IMAGINARIAMENTE 001</div>
</div>
<div class="row">
<div class="cols">SUPUESTO ID 002</div>
<div class="cols">SUPUESTA DESCRIPCION 002</div>
<div class="cols">SUPUESTO PRECIO 002</div>
</div>
</div>