使用ajax创建弹出窗口

时间:2011-05-03 06:34:52

标签: php ajax

我想使用ajax创建一个编辑弹出窗体。即当用户点击链接时,会弹出一个弹出窗口并编辑数据并保存。我可以用任何ajax框架吗?

2 个答案:

答案 0 :(得分:1)

是的,您可以自己创建XMLHttpRequest个对象,但使用框架可以节省数小时或数天的编码,并确保您的服务具有最大的浏览器兼容性。

答案 1 :(得分:-1)

是的,您可以使用我编写的以下功能,并进行了数周的优化。

function ajaxGET(url,span_or_div) {

    var httpRequest;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType('text/plain');
        }
    } 
    else if (window.ActiveXObject) { // IE ( yeah 200bytes wasted because of IE.. lol
        try {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                       try {
                            httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                           } 
                         catch (e) {}
                      }
            }
    if (!httpRequest) {
        alert('Giving up :( Cannot create an XMLHTTP instance');
        return false;
    }
    httpRequest.onreadystatechange = function() { 

         if (httpRequest.readyState == 1) {
            window.document.getElementById(span_or_div).innerHTML='Loading...'; 
         }
         if (httpRequest.readyState == 4) {
             if (httpRequest.status == 200) {
                 document.getElementById(span_or_div).innerHTML=(httpRequest.responseText);
             } else {
                 window.document.getElementById(span_or_div).innerHTML='<strong>Error 404</strong><br />Page Not Found.';
             }
         }
};
    httpRequest.open('GET', url, true);
    httpRequest.send('');
}
相关问题