Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting TypeError: invalid 'in' operand obj while fetching data using ajax

Below is my ajax call

 $(document).ready(function() {
     $("#blog").focusout(function() {
         alert('Focus out event call');
         alert('hello');
         $.ajax({
             url: '/homes',
             method: 'POST',
             data: 'blog=' + $('#blog').val(),
             success: function(result) {
                 $.each(result, function(key, val) {
                     $("#result").append('<div><label>' + val.description + '</label></div>');
                 });
             },
             error: function() {
                 alert('failure.');
             }
         });
     });
 });

I am getting 'TypeError: invalid 'in' operand obj ' error in my console

In advance thank you

like image 338
user2621586 Avatar asked Aug 27 '13 08:08

user2621586


2 Answers

Mention a dataType attribute in your ajax call.It consider text by default.That's why not able to iterate on result

dataType:'json'

Because your result should be array or json

like image 67
Swapnil Patil Avatar answered Nov 15 '22 16:11

Swapnil Patil


the 'result' in success function should be an array

like image 41
Manu M Avatar answered Nov 15 '22 17:11

Manu M