Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/02/2010, 04:56
Avatar de JuanKa
JuanKa
 
Fecha de Ingreso: septiembre-2004
Mensajes: 468
Antigüedad: 19 años, 7 meses
Puntos: 1
Evaluar return de una funcion php

Buenos dias a todos.

Estoy cambiando mi programacion a jquery y estoy usando el metodo $.ajax({...
y tengo algunos problemas.

Bueno al grano tengo la siguiente js:

Código:
function xxxxxx()
{
$.ajax({
    async       : true,
    type        : "POST",
    dataType    : "html",
    contentType : "application/x-www-form-urlencoded",
    url         : "index.php?seccion=home&modulo=camion&accion=save",
    data        : "sParams="+sElementos,
    beforeSend  : function(objeto){
                        $('#divEstadoProceso').html("<img src='./img/loading.gif' title='Loading...' />");
                        },                    
    success: function(msg){
                        $('#divEstadoProceso').css('display','none');
                                        
    timeout     : 40000,
    error       : function (xhr, desc, exceptionobj){    
                        $('#divEstadoProceso').css('display','none');                        
                        alert("El proceso ha fallado!");
                        alert(xhr.responseText);
                        alert(desc);
                        alert(exceptionobj);
                    }                    
});

}
internamente esta url :

index.php?seccion=home&modulo=camions&accion=save

me envia a una funcion:

Código PHP:
function grabarCamion()    
{    
    
$sParams $_REQUEST['sParams'];
    
$aRespuesta "INSERT INTO........... VALUES .........";
    
    if(
$aRespuesta[0]){                
        return(
"true|"."Los datos se han guardado ok.");
    }else{                
        return(
"false|"."Error al guardar los datos");
    }

Ahora con javascript con el metodo $.ajax quiero evaluar que haciendo un:

split('|') al return de php me muestre el alert del mensaje que quiero enviar algo como:

var aValores = str.split('|');

y yo pueda decir:

Código:
if( (aValores[0]===true) || (aValores[0]==='true') ) 
{
    alert(aValores[1])
}
else
{
    alert(aValores[1])
}
Como se puede hacer esto dentro del $.ajax({...


Gracias y saludos a todos