locked
How to send data to a web Service Using Winj.xhr

    Question

  • Hi everyone , I am new in Winjs coding I have data in a list .

    and i want to send that data to my json Web Service .I have a success to call to web service and i have the response so the web service is 

    working but the data doesn't seem to be sent. I dont know how to declare the data.

    I have many data to sent like(username,first_name,last_name,password) to my  Register.json

    The Register.json have this response after the execution:

    1. {
    2. "format": "json",
    3. "success": false,
    4. "errors": ["User name is empty"],
    5. "result": null
    6. }

    so i m sure that data doesnt be sent

    function Register() {
            var dataArray = [
           {
               username: "Marley",
               first_name: "dog",
               last_name: "ded",
               password: "pdre4252d",
           }];
            WinJS.xhr({
                url: "my_Base_URL/Register.json",
                type: "post",
                headers: { "Content-type": "application /x-www-form-urlencoded" },
                data: dataArray 

              // data:JSON.stringify(dataArray)

            }).done(
                  function complete(result) {
                      if (result.status === 200) {
                          console.log("Success: Response Text: " + result.responseText);
                      }
                      else {
                          console.log("Fail:Response Text:  " + result.responseText);
                      }
                  },

                  function error(error) {
                      console.log("error");
                     },
                  function progress(result) {
                    }

        );
        }

     

     I will be thinkful if someone give me some help.

     
    Saturday, March 23, 2013 9:52 PM

Answers

  • Hi,

    Please refer to the code as follow:

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


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 25, 2013 8:25 AM

All replies

  • Hi,

    Please refer to the code as follow:

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


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 25, 2013 8:25 AM
  • Thinks a lot

    Monday, March 25, 2013 8:35 AM