开发者

creating a pop up using just ajax

I want to create a edit pop up form using just ajax. i.e when user clicks on a link , a pop up comes up and he edits the data and sa开发者_StackOverflow中文版ves it. can i do this with out any ajax framework ?


Yes you can, you can always create XMLHttpRequest objects yourself, but using a framework will save you hours or days of coding and make sure your service has maximum browser compatibility.


Yes, you can use the following function which I wrote and did several weeks optimizing it.

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('');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜