Blog

  • This Blog is mean to introduce you people with XMLHttprequest basic operations with Netgem. First of all we will declare and define configuration for each type of data in MyFormWidget.js.

    var dataConfig = {  
        "json": {  
            "mimetype": "application/json",  
            "url":      "data.json"  
        },  
        "xml": {  
            "mimetype": "text/xml",  
            "url":      "data.xml"  
        },  
        "image": {  
            "mimetype": "application/image",  
            "url":      "data.png"  
        },  
        "bytebuffer": {  
            "mimetype": "text",  
            "url":      "data.bb"  
        }  
    };
            

    Then we will parse data from responsedata object.We can have responseText for text types as specified by w3c. But here, we will use reponseObject which will be a ByteBuffer.

    function CreateRequest(type)  
    {  
        var xhr = XMLHttpRequest();  
        var url = dataConfig[type].url;  
      
        NGM.trace("Load " + url);  
        xhr.open("GET", url, true);  
        xhr.overrideMimeType(dataConfig[type].mimetype);  
        xhr.onreadystatechange = function () {  
            if (xhr.readyState != 4) return;  
      
            ParseData(xhr.responseObject, type);  
      
            xhr = null;  
        }  
        xhr.send();  
    }  
    
            

    Start requests

    for (var i in dataConfig) {  
        CreateRequest(i);  
    }
    
            

    Now lets process and use the response data depending on thier types.

    function ParseData(data, type)  
    {  
        NGM.trace("Get " + type + " data: " + data);  
        switch (type) {  
            case "json":  
                NGM.dump(data, -1);  
                break;  
      
            case "xml":  
                var xml = data;  
                xml.dumpToMonitor();  
                break;  
      
            case "image":  
                var image = data;  
                image.animation.setEnable().zIndex(10).show(1000).move(500,200).start();  
                break;  
      
            case "bb":  
                var bb = data;  
                // Need privileged access  
                break;  
        } 
    

    Hope it Helps. Cheers :)) !

    Download sample

Tags: netgem