locked
Restful Webservice in metro app sample

    Question

  • Hi Techies.

    Need help on displaying list with the json webservice below is the snippet i am using but am getting invalid character . 

    would be gr8 help whats wrong in the code or simple snippet to access the json webservice .

    Web Service 

    http://mobile.vishcolors.com/GetEmployees.svc/EmployeeList?callback=jquey

    HTML CODE

    (function () {
        "use strict";
        var url = "http://mobile.vishcolors.com/GetEmployees.svc/EmployeeList?callback=jquey";
        WinJS.xhr({ url: url }).then(function (r) {
            var result = JSON.parse(r.responseText);
            var result =r.responseText;
          //  var result = JSON.parse(r.responseText);
            result = result.GetAllEmployeesMethodResult;
            var dataList = new WinJS.Binding.List(result);
            var publicMembers =
                {
                    itemList: dataList
                };
            WinJS.Namespace.define("DataExample", publicMembers);
        });
       
    })();
    

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>WebServicesDemo</title>
    
        <!-- WinJS references -->
        <link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
        <script src="//Microsoft.WinJS.1.0/js/base.js"></script>
        <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
    
        <script src="dataExample.js"></script>
    
    
        <!-- WebServicesDemo references -->
        <link href="/css/default.css" rel="stylesheet" />
        <script src="/js/default.js"></script>
    </head>
    <body>
        <p>Content goes here this is gr8</p>
        <div id="MsgContent">
           
     <div id="basicListView" 
        data-win-control="WinJS.UI.ListView"   data-win-options="{ itemDataSource : DataExample.itemList.dataSource }">
    
    </div>
    
    
        </div>
    </body>
    </html>
    

    Monday, September 17, 2012 1:09 PM

All replies

  • At what point are you getting the error?  It looks like you are immediately overriding the result variable.  Have you tried the code without this line: 
     var result =r.responseText;

    Dave Paquette @Dave_Paquette www.davepaquette.com

    Monday, September 17, 2012 3:15 PM
  • Error thrown at base.js (guess its a internal file for windows 8 )

    Bta I am new to windows 8 app developmet , any help on snippet to access the json service would be of gr8 help

    Tuesday, September 18, 2012 6:32 AM
  • Try this for your javascript:

    (function () {
        "use strict";
        var dataList = new WinJS.Binding.List();
        var url = "http://mobile.vishcolors.com/GetEmployees.svc/EmployeeList";
        WinJS.xhr({ url: url }).then(function (r) {
            var results = JSON.parse(r.responseText);
           
            results = results.GetAllEmployeesMethodResult;
            
            for (var i = 0; i < results.length; i++) {
                
                dataList.push(results[i]);
            }
            
        });
        var publicMembers =
                {
                    itemList: dataList
                };
        WinJS.Namespace.define("DataExample", publicMembers);
    })();
    First off, I removed the '?callback=jquey' from the url.  This seemed to be causing the invalid character error.  Next, I moved the definition of the DataExample namespace and creation of the initial list out of the function that was processing the results from the xhr.  


    Dave Paquette @Dave_Paquette www.davepaquette.com

    Tuesday, September 18, 2012 2:55 PM