Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have following code:
JavaScript
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
Updated 6-Dec-12 5:54am
v2
Comments
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.
BC @ CV 6-Dec-12 12:30pm    
So if you are returning data from the ajax call what does parameter id contain?
ZurdoDev 6-Dec-12 12:22pm    
If employee is undefined then id.d.employee must be undefined.
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

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900