Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8618857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:12:14+00:00 2026-06-12T06:12:14+00:00

I am returning an Employee object from my javascript ajax call.. var xhReq =

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:12:15+00:00Added an answer on June 12, 2026 at 6:12 am

    jQuery automatically parses the responseText into an object when it expects a JSON response.

    In vanilla JS, you can parse it with JSON.parse:

    var response = JSON.parse(xhReq.responseText),
        name = response.Name;
    

    Include this library also if you need compatibility with IE<=7: Crockford’s JSON2


    About eval

    It’s also possible to use eval to parse the responseText string into an object to have compatibility with IE<=7 as well without including extra code, but eval is evil.

    Of course, if your server always echoes well-formed JSON, it wouldn’t be a problem. I’d personally avoid eval and use the proper JSON.parse, but if you want to use eval for the IE<=7 compatibility without including extra code you can do it as follows:

    var response = eval('(' + xhReq.responseText + ')'),
        name = response.Name;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON response returning from an Ajax call but cannot seem to
Very simple Ajax request taking employee id and returning the user info as HTML
Returning information from webservice. I have made a class for the return object. But
I am returning a model from my controller that displays a grid. Works fine.
Possible Duplicate: returning multiple values from a function For example if you want a
NSString is returning as NULL while Importing from ViewController Class were i want to
When returning data from a DataReader I would typically use the ordinal reference on
I have inherited the maintenance of a database from a former employee in another
I am trying to execute a namedquery @NamedQuery(name=getEmployeeDetails,query=select e.username,e.email,e.image,e.firstname,e.lastname from Employee e where e.empid=?1)
I am new to unit testing. I have a method public List<Employee> GetEmployeeList() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.