The following should work
Code:
<script type="text/javascript">
$(document).ready(function(){
$("#boton").click(function(){
var campo = 'rut_consulta='+ jQuery("#rut_consulta").attr("value");
$.ajax({
type : "POST",
url : "scripts/search_workers.php" ,
traditional : true,
data : campo,
success : function(arrayPHP){
$("#rut").val(arrayPHP[0]);
$("#nombre").val(arrayPHP[1]);
}
});
})
})
</script>
Personally, I like to give my array indexes names, like so
PHP Code:
$msg = array('rut' => "1111111111", 'nobre' => "Pedro");
echo json_encode($msg);
As then you can access the data using the following:
Code:
<script type="text/javascript">
$(document).ready(function(){
$("#boton").click(function(){
var campo = 'rut_consulta='+ jQuery("#rut_consulta").attr("value");
$.ajax({
type : "POST",
url : "scripts/search_workers.php" ,
traditional : true,
data : campo,
success : function(arrayPHP){
$("#rut").val(arrayPHP['rut']); // if that doesn't work, try arrayPHP.rut, but I believe the original way I wrote it should work
$("#nombre").val(arrayPHP['nombre']); // if that doesn't work, try arrayPHP.nombre
}
});
})
})
</script>
Bookmarks