Wednesday, October 24, 2012

Object doesn't support property or method call in consuming JSON object from ASP.NET MVC (IE9)

Recently,
I've followed a simple tutorial regarding consuming JSON object in ASP.NET MVC. The error stated from the title of this post appears in IE9. The original snippet is this:
1:  $(document).ready(  
2:      $.getJSON(  
3:        'http://localhost:6222/home/customerjson',  
4:         function (item) {  
5:           $('#result') //show product name in   
6:            .html('<p>' + item.CurrentCustomer.CustomerName + '</p>');  
7:         }  
8:      )  
9:    );  
The solution is to enclose $.getJSON() in a function() statement based from the modified code below. The popup script just went away.
1:  $(document).ready(function(){  
2:        $.getJSON(  
3:          'http://localhost:6222/home/customerjson',  
4:           function (item) {  
5:             $('#result') //show product name in   
6:              .html('<p>' + item.CurrentCustomer.CustomerName + '</p>');  
7:           }  
8:        )  
9:      });   
Cheers!

0 comments:

Post a Comment