Ajax + simpleMVC
Publicado por Virginia (2 intervenciones) el 16/07/2007 20:27:06
Buenas tardes, quisiera que me ayudaran con la implementación de ajax dentro del modelo de programación simpleMVC, he hecho la función en ajax para eliminar un registro de la base de datos, el modelo y el controlador, aparentemente por separado todo funciona bien, el problema es cuando el controlador recibe del servicio la respuesta del proceso de eliminación, pues siempre envía vacio aunque efectivamente elimine el registro, entonces, qué estoy haciendo mal???
//----------------------------Controlador
public function eliminar_rol(){
$co_rol = $_REQUEST['co_rol'];
$accion = new SoapClient(SOAP_HOST."RolModelo&wsdl");
try{
$ok = $accion->EliminarRol($co_rol);
if($ok==1)
{
return 1;
}
}
catch(Exception $e){
return 0;
}
}
//-------------------------------Función AJAX
//Ajax
function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
peticion = new objetoAjax();
peticion1 = new objetoAjax();
ajax = new objetoAjax();
ajax1 = new objetoAjax();
function eliminar(co_rol){
id_codigo = co_rol;
if(confirm("¿Seguro desea eliminar "+id_codigo+"?")){
var url = "/rol/eliminar_rol?co_rol="+id_codigo;
peticion.open("POST",url,true);
peticion.onreadystatechange=function(){
if (peticion.readyState==4) {
//muestra resultados en esta variable
texto=peticion.responseText;
if(texto)
alert("Eliminación exitosa")
else
alert("Error en la eliminación")
}//fin if (ajax.readyState==4)
}//fin ajax.onreadystatechange=function()
//enviando los valores
peticion.send(null);
}
else
return;
}
//----------------------------Controlador
public function eliminar_rol(){
$co_rol = $_REQUEST['co_rol'];
$accion = new SoapClient(SOAP_HOST."RolModelo&wsdl");
try{
$ok = $accion->EliminarRol($co_rol);
if($ok==1)
{
return 1;
}
}
catch(Exception $e){
return 0;
}
}
//-------------------------------Función AJAX
//Ajax
function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
peticion = new objetoAjax();
peticion1 = new objetoAjax();
ajax = new objetoAjax();
ajax1 = new objetoAjax();
function eliminar(co_rol){
id_codigo = co_rol;
if(confirm("¿Seguro desea eliminar "+id_codigo+"?")){
var url = "/rol/eliminar_rol?co_rol="+id_codigo;
peticion.open("POST",url,true);
peticion.onreadystatechange=function(){
if (peticion.readyState==4) {
//muestra resultados en esta variable
texto=peticion.responseText;
if(texto)
alert("Eliminación exitosa")
else
alert("Error en la eliminación")
}//fin if (ajax.readyState==4)
}//fin ajax.onreadystatechange=function()
//enviando los valores
peticion.send(null);
}
else
return;
}
Valora esta pregunta


0