RESPONDER UNA PREGUNTA

Si para responder la pregunta, crees necesario enviar un archivo adjunto, puedes hacerlo a traves del correo [email protected]

    Pregunta:  67012 - ENVIO DE AJAX DUPLICA DATOS DESDE VENTANA MODAL
Autor:  Alexis Rebolledo
Hola a todos, recurro a ud. para que me ayuden a resolver un problema que me tiene loco, tengo un formulario en una ventana modal para lo cual ocupe jquery ui, le inserte unos botones a través de código con la misma librería, para enviar los datos ocupa la función serialize(), el problema que al hacer click en el botón al enviar los datos los hace dos veces, la primera con datos y la segunda variable sin datos , por lo cual no recibo respuesta .

el código HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>

<script type="text/javascript">
$(document).ready( function () {
$('#example').dataTable( {
"bJQueryUI" : true,
"sPaginationType": "full_numbers",
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "../jquery/copy_csv_xls_pdf.swf",
"aButtons": [
{
"sExtends" : "copy",
"sButtonText" : "Copiar"
},
{
"sExtends" : "print",
"sButtonText" : "Imprimir"
},
{

"sExtends": "collection",
"sButtonText": "Guardar Como",
"aButtons": [ "csv", "xls", "pdf" ]
}
]
}

} );
$('#example tbody tr ').live('click', function () {
var fila = $('td', this);
var dataString = $(fila[0]).text();
$('#hora').val(dataString);
$('#pacientes').dialog('open');
return false



});
$('#pacientes').dialog({
title : "Pacientes",
modal: true,
autoOpen: false,
show: 'explode',
hide:'blind',
width:'450',
height:'auto',
resizable: false,
buttons :{
"Limpiar" : function (){
$('#id').val('');
$('#nombre').val('');
$('#paterno').val('');
$('#materno').val('');
$('#fechanac').val('');
$('#fono').val('');
$('#celular').val('');
$('#email').val('');
$('#direccion').val('');
$('#id').focus();

},
"Asignar" : function (){
var dataString = $('#ficha').serialize();
$.ajax({
url : "horapaciente.php",
data : dataString,
type : "POST",
success: function(data) {
$('#respuesta').empty();
$('#respuesta').html(data);
}
})
},
"Borrar" : function(){

}
},
close: function(){
$('#ficha input[type="text"]').val(' ');
}
});

} );
</script>

</head>
<body>
<?php
include ('../lib/conectar.php');
$conectar = conectar();

$diaenviado = $_POST['date'];
if(empty($diaenviado)){
$sql = "SELECT * FROM hora_prestador WHERE fecha='". date("Y-m-d")."'";
global $conectar;
$resultado = mysql_query($sql,$conectar);
echo '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" style="border-bottom: 1px solid">
<thead>
<th>id</th>
<th>Hora</th>
<th>Fecha</th>
<th>idprestador</th>
<th>estado</th>
<th></th>
<th></th>
</thead>
<tbody align="center">';

while ($datos = mysql_fetch_array($resultado)) {
echo "<tr><td>".$datos['id']."</td>
<td>".$datos['hora']."</td>
<td>".$datos['fecha']."</td>
<td>".$datos['idprestador']."</td>
<td>".$datos['estado']."</td>
<td><a id='ventana1'><img src='../images/user.png' style=' cursor: pointer' /></a></td>
<td><a class='ventana'><img src="../images/tick.png" title="Confirmar Asistencia" style="cursor:pointer"/></a></td></tr>";

}
echo '</tbody>
<tfoot>
</tfoot>
</table>';

}
else{
$sql = "SELECT * FROM hora_prestador WHERE fecha='".$diaenviado."'";
global $conectar;
$resultado = mysql_query($sql,$conectar);
echo '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" style="border-bottom: 1px solid">
<thead>
<th>id</th>
<th>Hora</th>
<th>Fecha</th>
<th>idprestador</th>
<th>estado</th>
<th></th>
<th></th>
</thead>
<tbody align="center">';

while ($datos = mysql_fetch_array($resultado)) {
echo "<tr><td>".$datos['id']."</td>
<td>".$datos['hora']."</td>
<td>".$datos['fecha']."</td>
<td>".$datos['idprestador']."</td>
<td>".$datos['estado']."</td>
<td><a id='ventana1'><img src='../images/user.png' style=' cursor: pointer' /></a></td>
<td><a class='ventana'><img src="../images/tick.png" title="Confirmar Asistencia" style="cursor:pointer"/></a></td></tr>";

}
echo '</tbody>
<tfoot>
</tfoot>
</table>';
}



?>
<div id="pacientes">
<?php
include 'pacientes.php';
?>

</div>



</body>
</html>

La ventana modal la llamo desde otro archivo php que no tiene mas que un par de tag tipo input, y el otro archivo php que trae la respuesta solo tiene unos echo con los mismo datos que envío para probar la respuesta , cuando abro la venta del firerbug para ver la consola, envia los datos así:

nombre = Juan
nombre =
paterno = Perez
paterno =
email = [email protected]
email =

la primera con datos, la segunda no, y reviso y reviso y no entiendo porque hace eso, desde ya les doy las gracias por su ayuda.


Nombre
Apellidos
Correo
Comentarios