7

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

2
  • are you getting alert..? Commented Aug 27, 2013 at 8:22
  • Your code is missing a closing });. Is this bad cut-and-paste or the underlying cause? Commented Aug 27, 2013 at 8:23

3 Answers 3

14

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

Sign up to request clarification or add additional context in comments.

Comments

1

the 'result' in success function should be an array

Comments

0

Shouldn't data be an object?

data: {
    blog: $('#blog').val()
},

1 Comment

No; api.jquery.com/jQuery.ajax states that it can be an object or a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.