• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1169
  • Last Modified:

JQuery - $.ajax returns UNDEFINED

I'm calling the following:  The service works and returns  JSON - tested in browser and fiddler
But when I try and parse the response I get UNDEFINED.

Here's the code

 $.ajax({
                            type: "GET",
                            url: url,
                            data: params
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: OnSuccess,
                            error: OnError
                        });



  function OnSuccess(data, status) {

           alert(status);
           alert(data);    // UNDEFINED

 var json = JSON.parse(data)   // UNEXPECT TOKEN 0




ANY IDEAS?
THX
0
JElster
Asked:
JElster
  • 4
  • 2
2 Solutions
 
fostersoftCommented:
Do you have check what the services is suppose to return with the same params ?

Can you enter in debug mode to see what you function really return to your ajax query ?
0
 
JElsterAuthor Commented:
In debugger ... look correct. but how do I get the values and why the errors?

data:  Object
  Get_UserResult: Object
   FIRSTNAME: "John"
   LASTNAME: "Smtih
0
 
fostersoftCommented:
Your services is in wich programming language ?

First i think you don't need to do " JSON.parse(data) " because the result is suppose to be an object. You be suppose to call directly your property. Ex:
ALERT(data.FIRSTNAME)

Open in new window

If your in asp.net(not mvc page but in an aspx page) you can try
data.m.FIRSTNAME 

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
JElsterAuthor Commented:
WCF Service JSON

data.FIRSTNAME is Undefined
??????
0
 
JElsterAuthor Commented:
WebMethod  had
BodyStyle = WebMessageBodyStyle.Wrapped,
Which puts a the service name around the JSON.

I remove it and it works.

data:  Object
  Get_UserResult: Object
   FIRSTNAME: "John"
   LASTNAME: "Smtih
0
 
JElsterAuthor Commented:
worked
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now