1

I am getting XML response from ajax and then I am trying to store it in sessionStorage but I cannot retrieve it.

$.ajax({
        url: '/webservice.svc/getProfile',
        data: { "memberId": $(authenticateResponse).find("memberId").text() },
        method: "GET",
        async: false,
        success: function (d) {
            sessionStorage.clear();
            sessionStorage.setItem('ALMS', d);
        }
    });

When I try to retrieve

console.dirxml(sessionStorage.ALMS)
[object XMLDocument]
console.dirxml($(sessionStorage.ALMS)) 

What I am doing wrong !!

Milind
  • 1,855
  • 5
  • 30
  • 71

1 Answers1

2

The issue you have is that sessionStorage can only hold strings. Due to this the XMLDocument is being coerced using toString(), hence the value you're seeing.

To fix this you need to serialise the XMLDocument manually before saving it. Try this:

$.ajax({
  url: '/webservice.svc/getProfile',
  data: { 
    memberId: $(authenticateResponse).find("memberId").text() 
  },
  method: "GET",
  success: function (d) {
    sessionStorage.clear();
    sessionStorage.setItem('ALMS', new XMLSerializer().serializeToString(d));
  }
});

Also note that I removed async: false as it's incredibly bad practice.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339