Introduction to XMLHttpRequest object extensions in Netgem

Posted By : Ajit Jati | 15-Nov-2013

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

About Author

Author Image
Ajit Jati

Ajit is an proficient Project Manager specializing in Mobile technologies. He possesses extensive development experience in Titanium, Android, Kotlin, Roku, and PHP. Ajit has successfully delivered various projects in the OTT, AR/VR, and Travel industries. His skill set includes developing and maintaining project plans, schedules, and budgets, ensuring timely delivery while staying within the allocated budget. He excels in collaborating closely with clients to define project scope and requirements, establish project timelines and milestones, and effectively manage expectations. He conducts regular project status meetings, ensuring effective communication and providing updates to clients and stakeholders on project progress, risks, and issues. Furthermore, Ajit takes on the role of a coach and mentor for team,offering guidance on project management best practices and assisting in their skill development.

Request for Proposal

Name is required

Comment is required

Sending message..