Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 06, 2013 02:43 PM by SGWellens
Participant
1520 Points
775 Posts
Jan 06, 2013 10:22 AM|LINK
Following is the markup of my MVC view:
<div style="visibility:visible;"> var data = [ {"id":"1", "ui_bgcolor":"Green", "ui_forecolor": "Black"}, {"id":"2", "ui_bgcolor":"Amber", "ui_forecolor": "Black"}, {"id":"3", "ui_bgcolor":"Red", "ui_forecolor": "White"} ] </div> <script type="text/javascript"> function SetGradeDLLItemStyling() { $.each(data, function (i) { alert(data[i].UIBackgroundColor); }); } </script>
I am receiving $.data is undefined error in script block. What is wrong here?
Contributor
6109 Points
1167 Posts
Jan 06, 2013 01:47 PM|LINK
did you add jquery library in this page ? if not then please add
All-Star
126029 Points
10309 Posts
Moderator
Jan 06, 2013 02:43 PM|LINK
Your data variable has been defined outside of script tags so Javascript cannot 'see' it.
Plus, UIBackgroundcolor is the wrong variable name.
Here's a working version: http://jsfiddle.net/ufXX7/
nirman.doshi
Participant
1520 Points
775 Posts
$.data is undefined
Jan 06, 2013 10:22 AM|LINK
Following is the markup of my MVC view:
<div style="visibility:visible;"> var data = [ {"id":"1", "ui_bgcolor":"Green", "ui_forecolor": "Black"}, {"id":"2", "ui_bgcolor":"Amber", "ui_forecolor": "Black"}, {"id":"3", "ui_bgcolor":"Red", "ui_forecolor": "White"} ] </div> <script type="text/javascript"> function SetGradeDLLItemStyling() { $.each(data, function (i) { alert(data[i].UIBackgroundColor); }); } </script>I am receiving $.data is undefined error in script block. What is wrong here?
Software Developer
Vadodara, India
SohailShaikh
Contributor
6109 Points
1167 Posts
Re: $.data is undefined
Jan 06, 2013 01:47 PM|LINK
did you add jquery library in this page ? if not then please add
Sohail Shaikh
SGWellens
All-Star
126029 Points
10309 Posts
Moderator
Re: $.data is undefined
Jan 06, 2013 02:43 PM|LINK
Your data variable has been defined outside of script tags so Javascript cannot 'see' it.
Plus, UIBackgroundcolor is the wrong variable name.
Here's a working version: http://jsfiddle.net/ufXX7/
My blog