Click here to Skip to main content
12,820,546 members (29,409 online)
Rate this:
Please Sign up or sign in to vote.
See more: Javascript jQuery JSON
I have following code:
 var employee = '';
        function FillEmployee()
                type: "POST",
                url: 'http://localhost:1732/GridViewExample/ClientServerInterface.aspx/GetEmployee',
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                async: false,
                success: function (id)
                      employee = id.d.employee;

in above code variable employee gives undefined error but i have already globaaly defined.
Posted 6-Dec-12 6:37am
Updated 6-Dec-12 6:54am
BC @ CV 6-Dec-12 11:45am
Is it possible that id.d.employee is giving you the undefined error? Are you sure you're getting back the data you expect from the ajax call?
Sandeep Shekhawat 6-Dec-12 12:01pm
Yes, It is returning data. I have debug code and checked it.
ryanb31 6-Dec-12 12:22pm
If employee is undefined then id.d.employee must be undefined.
BC @ CV 6-Dec-12 12:30pm
So if you are returning data from the ajax call what does parameter id contain?
Adam R Harris 6-Dec-12 13:21pm
Using a javascript debugger (IE Developer Tools), set a break point and add a watch for id.d.employee and employee then see what the value coming back from the ajax call is and if its getting set properly. All the other comments are correct, looking at the code the only way employee would be undefined is because id.d.employee is undefined.

You are initializing the employee variable to '' so the only possible way it could be undefined is if id.d.employee is undefined or if it is getting set to undefined somewhere else in your code. After you set your break point double check the property name as i'm fairly certain its just a typo that is causing your problem.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

change variable name
var employee = '';
to some other name
var emp = '';
and use that variable in the code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100