Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/06/2013, 06:41
JONATHAN13
 
Fecha de Ingreso: abril-2012
Mensajes: 6
Antigüedad: 12 años
Puntos: 0
Consulta Doble en ajax

Buen día quisiera ver si me pueden ayudar, en el siguiente codigo que les mostrare, tengo un error con los .ajax, se ejecutan 2 veces y nose la razon del porque, creando en algunos casos registros duplicados pero con diferente id. Espero me puedan ayudar.. saludos...


este es el .js

Código:
$(document).ready(function(){



		function error(){

			$(function() {
				$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
				$( "#error" ).dialog({
					buttons:{
								OK: function() {
									$( this ).dialog( "close" );
								}
							},
					resizable: false,						
					height: 280,
					width: 600,
					modal: true
				});
				return false;
			});

		}



		function cliente(){

			$(function() {
				$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
				$( "#cliente" ).dialog({
					buttons:{
								OK: function() {
									$( this ).dialog( "close" );
								}
							},
					resizable: false,						
					height: 280,
					width: 600,
					modal: true
				});
				return false;
			});

		}



		function formu(){

			$(function() {
				$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
				$( "#formu" ).dialog({
					buttons:{
								OK: function() {
									$( this ).dialog( "close" );
								}
							},
					resizable: false,						
					height: 280,
					width: 600,
					modal: true
				});
				return false;
			});

		}



		function des(){

			$(function() {
				$( "#dialog:ui-dialog" ).dialog( "destroy" );
		
				$( "#des" ).dialog({
					buttons:{
								OK: function() {
									$( this ).dialog( "close" );
								}
							},
					resizable: false,						
					height: 280,
					width: 600,
					modal: true
				});
				return false;
			});

		}




		$("#crear").click(function(){
		
			if($("#tx2c").val() == false){
				error();
				return false;
			}


			else
			{
				var misId = {
								"nombre" : $("#tx2c").val()
						   };
				$.ajax({
					data: misId,
					url:  "admin/rtcliente.php",
					type: "post",
					success: function(datos){
												if(datos=="cliente"){cliente();}
												else
													{
														$("#tx5c").val(datos);
														$("#puno").hide('fold',600);
														$("#pdos").show('fold',600);
													}
									   		}
									   		
				});
			}	
		

		});
		//fin boton	


		$("#creard").click(function(){
		
		if($("#tx4c").val() == false){
			formu();
			return false;
			}
		if($("#tx5c").val() == false){
			formu();
			return false;
			}

		else
			{
				var datos= {
							  "descuento" : $("#tx4c").val(),
							  "idser" : $("#tx3c").val(),
							  "idtipo" : $("#tx5c").val()
						   };
				$.ajax({
					data: datos,
					url:  "admin/rtcliented.php",
					type: "post",
					success: function(texto){
												if(texto == "des"){des();}
									   		}
				});						   
			}

	});	






//Fin Jquery
});

este es el .php de uno de los ajax, los 2 se ejecutan 2 veces

Código:
<?php

	require('../session.php');
	if ($_SESSION['tipo'] != "Admin" ){
			session_destroy();
			header('Location: ../index.html');
			exit();
		}

		
	$nom=$_POST['nombre'];
	

			//If Principal
	if( isset($_POST['nombre']) )
		{

			$bu_serv="CALL bu_tipo_clientes('".$nom."')";
			include("../conexion.php");
			$consulta=mysql_query($bu_serv,$conexion) or die ("Error".mysql_error());
			$resultado=mysql_num_rows($consulta);
			mysql_close($conexion);
			//if resultado
			if ($resultado == 1)
				{	
					echo ("cliente");
				}
			//fin if resultado
			//else resultado
			else
				{
					
					include("../conexion.php");
					$pro="CALL in_tipos_clientes('".$nom."','".$_SESSION['ide']."')";
					mysql_query($pro,$conexion) or die ("Error: ".mysql_error());
					mysql_close($conexion);

					include("../conexion.php");
					$bu_tip="CALL bu_tipo_clientes('".$nom."')";
					$con=mysql_query($bu_tip,$conexion) or die ("Error".mysql_error());
					$arreglo=mysql_fetch_array($con);
					$idn= $arreglo['id_tipo'];
					mysql_close($conexion);

					echo($idn);

				}
			//fin else resultado
					
		}
		//fin If principal
		//Else Principal
	else
		{
			header('Location: ../admin.html');

		}
		//Fin else Principal
 
	
?>