locked
navigate to another HTML using windows 8 apps

    Question

  • Hi...

                               

    My code is:
            var xhr = new XMLHttpRequest();
            xhr.open("POST", "http://www.rest.net/services/abc.svc/json/GetXml", true);
            xhr.responseType = "text";
            xhr.setRequestHeader("Content-Type", "text/xml;charset=UTF-8");
            var packet = '<?xml version="1.0" encoding="utf-8" ?><CompanyRequest xmlns="http://schemas.datacontract.org/2004/07/abc.DomainModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><CompanyName>company</CompanyName></CompanyRequest>';
            xhr.onreadystatechange = function () {
                if (xhr.readyState==xhr.DONE) {               
                    // window.console.log(blob);
                    var parser = new DOMParser();
                    var response = parser.parseFromString( xhr.responseText, "text/xml");
                    var n = response.getElementsByTagName("GetCompanyResponse");               
                    for (var i = 0; i < n.length; i++) {
                        var p = n[i].getElementsByTagName("CompanyList");
                        for (var j = 0; j < p.length; j++) {
                            var l = p[j].getElementsByTagName("Company");
                            for (var k = 0; k < l.length; k++) {
                                var a = l[k].getElementsByTagName("Id")[0].firstChild.nodeValue;

                                if (a != null) {
                                    sessionStorage.setItem(1, a);
                                    WinJS.Navigation.navigate("Search.html");
                                }
                                //document.getElementById("result").value = a;
                            }
                        }
                    }
                }
            } xhr.send(packet);

    I am very new to this. I want to navigate to search.html page on button click. But it is not going so...what's wrong with it i cant understand...help me


    • Edited by vidhya5 Monday, November 26, 2012 9:47 AM
    Monday, November 26, 2012 9:30 AM

Answers

  • What you are doing in the code above is called "Screen Scraping". To correctly understand how the click of the "Search" button works, you can use tools such as Fiddler or even the "F12 Developer Tools" of Internet Explorer 10 and then use the "Network" tab to understand what request leads to the correct response. Once you understand the request that generates the appropriate response, you can try to mimic the same HTTP request in your code and get the same HTTP response.

    Thanks,

    Prashant

    Tuesday, November 27, 2012 12:34 AM
    Moderator