Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JQuery - $.ajax returns UNDEFINED

Posted on 2014-01-21
6
Medium Priority
?
1,114 Views
Last Modified: 2014-01-26
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
Comment
Question by:JElster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 1

Expert Comment

by:fostersoft
ID: 39798966
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
 
LVL 1

Author Comment

by:JElster
ID: 39798977
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
 
LVL 1

Assisted Solution

by:fostersoft
fostersoft earned 2000 total points
ID: 39798987
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
Independent Software Vendors: 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!

 
LVL 1

Author Comment

by:JElster
ID: 39798997
WCF Service JSON

data.FIRSTNAME is Undefined
??????
0
 
LVL 1

Accepted Solution

by:
JElster earned 0 total points
ID: 39799047
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
 
LVL 1

Author Closing Comment

by:JElster
ID: 39809863
worked
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question