0

I am making a mobile application using PhoneGap. To authenticate a user, I send the data using the .ajax() command in jQuery. This sends me a cookie in return and I am able to access the cookie and the contents of the cookie.

The next step is to make another API request and this involves sending the cookie that I received in the previous step. I am trying to do something like this:

$.ajax({
       url:"https://SomeDomain.asmx/getProjectList",
       type:"jsonp",

       xhrFields: {
               withCredentials: true
       },

       beforeSend: function(xhr) {
       xhr.setRequestHeader("Cookie", "ASP.NET_SessionId");
       },

       contentType: "application/json; charset=utf-8",
       data: JSON.stringify(textJson),

       success: function(result){
              alert('success');
       },
       error: function(result){
              console.log(result);
       }

});

At the moment, the response is the text of a 404 Not Found error page. Is it because there is something wrong with the cookie that I am attaching to the request ?

PS - I don't have access to the server side code. I'm just sending data to a web service.

4

1 に答える 1

0

Following will help.

  1. Set cookies value inside hidden fields and get those hidden value using jquery and pass it along with data in $.ajax call.

  2. if you do not want to use hidden fields then jQueryCookies plugin will help to read cookies and then pass it as you need.

于 2013-02-14T04:53:38.157 に答える