使用Ajax生成一个警告框 [英] Using Ajax to generate an alert box

查看:110
本文介绍了使用Ajax生成一个警告框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想确认一些数据是否存储在数据库中的后,弹出一个警告框。如果存储,它会提醒保存,否则不会保存。

这是我的ajaxfunction

  AjaxRequest.POST(
              {
                URL:GroupsHandler.php
                ,的onSuccess:功能(creategroupajax){警报('救了!) }
                onError的:功能(creategroupajax){警报(不保存);}
              }
            );
 

但现在它显示AjaxRequest是不确定的。

请帮忙如何解决这个

感谢

解决方案

 函数阿贾克斯(data_location){
    VAR XML;
    尝试 {
        XML =新XMLHtt prequest();
    }赶上(错误){
        尝试 {
            XML =新的ActiveXObject(MSXML2.XMLHTTP);
        }赶上(错误){
            尝试 {
                XML =新的ActiveXObject(Microsoft.XMLHTTP);
            }赶上(ERROR1){
                //
            }

        }
    }
    xml.onreadystatechange =功能(){
        如果(xml.readyState == 4和&安培; xml.status == 200){
            警报(可用数据);
        }
    }
    xml.open(GET,data_location,真正的);
    xml.send(空);

}


在window.onload =功能(){
    阿贾克斯(data_file_location);
}
 

Hi I want to pop up an alert box after checking whether some data is stored in the database. If stored, it will alert saved, else not saved.

This is my ajaxfunction

      AjaxRequest.POST(
              {
                'url':'GroupsHandler.php'
                ,'onSuccess':function(creategroupajax){ alert('Saved!'); }
                ,'onError':function(creategroupajax){ alert('not saved');}
              }
            );

but now it show AjaxRequest is undefined.

please help how to fix this

Thanks

解决方案

function Ajax(data_location){
    var xml;
    try { 
        xml = new XMLHttpRequest();
    } catch (err){
        try { 
            xml = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (error){
            try {
                xml = new ActiveXObject("Microsoft.XMLHTTP");   
            } catch (error1){
                //
            }

        }
    }
    xml.onreadystatechange = function(){
        if(xml.readyState == 4 && xml.status == 200){
            alert("data available");
        }
    }
    xml.open("GET", data_location, true);
    xml.send(null);

}


window.onload = function(){
    Ajax("data_file_location");
}

这篇关于使用Ajax生成一个警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆