Click here to Skip to main content
11,715,043 members (61,148 online)
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 5:37am
Edited 6-Dec-12 5: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 Sergey Alexandrovich Kryukov 520
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2015
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