-
-
Save carloscarcamo/ee30b777ac88c9ffee84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
function ajaxCall(url, parameters, successCallback) { | |
$.ajax({ | |
type: 'POST', | |
dataType: 'json', //la funccion success te devolvera un json | |
url: url, | |
data: parameters, | |
success:successCallback, //callback | |
error: function(xhr, textStatus, errorThrown) { | |
console.log('error'); | |
} | |
}); | |
} | |
function callback(){ | |
var numbe; //window.Tele.getTelephoneNumber(); | |
var uid="398f46273cfb9adf";//window.Tele.getTelephoneNumber(); | |
//var uuiid=device.uuid; | |
var dataPhone={ | |
codigo:uid | |
,numero:number | |
} | |
if(number!= null){ | |
ajaxCall("http://dev2.mirebate.com/mobile/buscarNumero.php",dataPhone, function (response){ | |
//var obj=eval("("+response+")"); | |
/** | |
* en la llamada ajax has fefinido lo siguiente: | |
* dataType: 'json' | |
* entonces ya no es necesario convertir el resultado a json | |
* peor aun usar eval es antipattern | |
* si de verdad necesitas convertir un string a json usa mejor | |
* JSON.parse() | |
* https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/JSON/parse | |
*/ | |
if(response.length>0){ | |
var fechaUser=response[0].fechahoy; | |
var fechaExp=response[0].fechaExp; | |
if(fechaUser<=fechaExp){ | |
alert("hola desde termsAccepted");//termsAccepted(Db); | |
}else{ | |
//Toast.showShortTop('Lo sentimos el periodo de uso de la aplicacion a expirado'); | |
alert("Lo sentimos el periodo de uso de la aplicacion a expirado"); | |
} | |
}else{ | |
alert("No hay datos en la db");//phonePage(Db); | |
} | |
}); | |
//var obj=eval("("+response+")"); no usar eval | |
//este codigo a continuacion es que el que debes meter en el callback | |
/*if(obj.length>0){ | |
var fechaUser=obj[0].fechahoy; | |
var fechaExp=obj[0].fechaExp; | |
if(fechaUser<=fechaExp){ | |
alert("hola desde termsAccepted");//termsAccepted(Db); | |
}else{ | |
//Toast.showShortTop('Lo sentimos el periodo de uso de la aplicacion a expirado'); | |
alert("Lo sentimos el periodo de uso de la aplicacion a expirado"); | |
} | |
}else{ | |
alert("No hay datos en la db");//phonePage(Db); | |
}*/ | |
}else{ | |
ajaxCall("http://dev2.mirebate.com/mobile/buscarUID.php",dataPhone, function (response) { | |
if(response.length>0){ | |
var fechaUser=response[0].fechahoy; | |
var fechaExp=response[0].fechaExp; | |
if(fechaUser<=fechaExp){ | |
termsAccepted(Db); | |
}else{ | |
alert("Lo sentimos el periodo de uso de la aplicacion a expirado"); | |
} | |
}else{ | |
alert("No hay datos en la db"); //phonePage(Db); | |
} | |
}); | |
} | |
alert("Lo sentimos el periodo de uso de la aplicacion a expirado"); | |
var number; //window.Tele.getTelephoneNumber(); | |
var uid="398f46273cfb9adf";//device.uuid; | |
var dataPhone={ | |
numero:number | |
,codigo:uid | |
} | |
if(number!= null){ | |
ajaxCall("http://dev2.mirebate.com/mobile/buscarNumero.php",dataPhone, function (response){ | |
if(response.length>0){ | |
var fechaUser=response[0].fechahoy; | |
var fechaExp=response[0].fechaExp; | |
if(fechaUser<=fechaExp){ | |
alert("termsAccepted(Db);"); | |
}else{ | |
//Toast.showShortTop | |
alert('Lo sentimos el periodo de uso de la aplicacion a expirado'); | |
} | |
}else{ | |
phonePage(Db); | |
} | |
}); | |
}else{ | |
ajaxCall("http://dev2.mirebate.com/mobile/buscarUID.php",dataPhone, function (response){ | |
var obj=append ("("+response+")"); //no se que haces aca asi que lo dejo asi | |
if(obj.length>0){ | |
var fechaUser=obj[0].fechahoy; | |
var fechaExp=obj[0].fechaExp; | |
if(fechaUser<=fechaExp){ | |
termsAccepted(Db); | |
}else{ | |
//Toast.showShortTop | |
alert('Lo sentimos el periodo de uso de la aplicacion a expirado'); | |
} | |
}else{ | |
alert("hola hoy es"+fechaUser); | |
phonePage(Db); | |
} | |
}); | |
} | |
/** | |
* Notar algo: | |
* fechaUser la estas creando al recibir datos de la db | |
* por medio de ajax, pero todo lo estas pasando dentro del callback | |
* a la funcion success del ajax dentro de ajaxCall | |
* entonces esa variable solo vive dentro de ese callback y no estara disponible | |
* globalmente, por lo que las lineas a continuacion no funcioanran dado que | |
* fechaUser no ha sido definida ni inicializada fuera del callback | |
* asun si la definis afuera y le pasas los valores en la respuesta ajax, | |
* no te funcionara como esperas, dado que ajax es asyncrono y posiblemente el codigo ajax | |
* termine mucho antes de llegar a esta parte de tu codigo. | |
*/ | |
alert("hola hoy es"+fechaUser); | |
termsAccepted(Db); //phonePage(Db); | |
} | |
</script> | |
</head> | |
<body> | |
<span id="res"> | |
<input type="button" id="enviar" onclick="callback()" value="Insertar"/> | |
</span> | |
</body | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment