Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript jQuery JSON
I have following code:
 var employee = '';
        function FillEmployee()
        {           
            $.ajax({
                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;
                     PopulateValueDropDown(employee);
                }
            });
        } 
in above code variable employee gives undefined error but i have already globaaly defined.
Posted 6-Dec-12 6:37am
Edited 6-Dec-12 6:54am
v2
Comments
BC @ CV at 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 at 6-Dec-12 12:01pm
   
Yes, It is returning data. I have debug code and checked it.
BC @ CV at 6-Dec-12 12:30pm
   
So if you are returning data from the ajax call what does parameter id contain?
ryanb31 at 6-Dec-12 12:22pm
   
If employee is undefined then id.d.employee must be undefined.
Adam R Harris at 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
good
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.
  Permalink  

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

  Print Answers RSS
0 DamithSL 390
1 Maciej Los 217
2 OriginalGriff 213
3 BillWoodruff 130
4 Garth J Lancaster 90
0 OriginalGriff 7,953
1 DamithSL 6,139
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,293
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2014
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