locked
sending JSon request in store apps using javascript RRS feed

  • Question

  • I am trying to POST a JSON request from my windows store apps using javascript

    WinJS.xhr({

                type:

    "post",

                url:

    "http://<ip address>/sna/Login?deviceid=2EB27D76FDED54BE93304E6E0FC52B95",

               

    headers: { "Content-type": "application/json", "version":"31.0_320x480","request":"getfiles","screen":"Smart Client","width":"320","height":"480" },


               

    data: JSON.stringify({ someProperty: "DK" })


            }).done(

    function(args) {

                    message =

    "success";

            },

               

    function(args) {

                    message =

    "error";

                },

               

    function(args) {

                    message =

    "error";

                });

    but the call back goes into Error with status code = 0. wanted to understand where its failing.


    thanks & regards chandresh soni


    Thursday, November 1, 2012 5:45 AM

Answers

  • Hi,

    Please refer to the example as follow:

    function CallData() {
    
            var person = { 'Name': 'Name'};
            WinJS.xhr({
                type: "POST",
                url: "http://172.18.28.109/jquery/WebService.asmx/Save",
                headers: { "Content-type": "application/json" },
                data: JSON.stringify(person)
            }).then(function complete(request) {
                //var stuListNew = JSON.parse(request.responseText);
                var resdata = request.responseText;
            }, function error(er) {
                var err = er.statusText;
            });
        }


    Please mark the replies as answers if they help or unmark if not.
    If you have any feedback about my replies, please contact msdnmg@microsoft.com
    Microsoft One Code Framework

    • Marked as answer by Song Tian Tuesday, November 13, 2012 6:47 AM
    Thursday, November 1, 2012 9:27 AM