Home:ALL Converter>Returning A Custom Object From XMLHttpRequest Object

Returning A Custom Object From XMLHttpRequest Object

Ask Time:2012-09-29T05:22:00         Author:Nick LaMarca

Json Formatter

I am returning an "Employee" object from my javascript ajax call..

var xhReq = new XMLHttpRequest();
xhReq.open("POST", "MobileClientService.svc/REST/TestReturnEmployee", false);
xhReq.send(null);

var serverResponse = xhReq.responseText;

What is returned is JSON data. I would like to return an Object that has the structure of my Employee object so I could write in javascript..

var name = serverResponse.Name;

Is this possible to do or is my only choise to parse the returned JSON string? No I cant use jquery (it returns the object fine that way) it must be javascript only.

Author:Nick LaMarca,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/12647546/returning-a-custom-object-from-xmlhttprequest-object
yy