Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: invalid 'in' operand obj in jquery 1.9.1 version

Tags:

jquery

$.ajax({
    async: false,
    type: "POST",
    url: url+"module/listing/"+projectId,
    data: "ajax=true",
    success: function(response) {
        $.each(response, function(key, val) {
        alert(val.id);
        });
    }
});

This is my code. Ajax success I am getting JSON response. Response is in array format. And I want to alert the response. But getting error "TypeError: invalid 'in' operand obj" for JQuery 1.9.1 version.

like image 301
user2392605 Avatar asked May 17 '13 06:05

user2392605


3 Answers

I got this error after I encoded twice a JSON array. Maybe it will help anybody.

like image 51
Octavian Avatar answered Oct 08 '22 16:10

Octavian


success: function(response) {
        response=JSON.parse(response);
        $.each(response, function(key, val) {
        alert(val.id);
        });
    }
like image 24
Amit Garg Avatar answered Oct 08 '22 15:10

Amit Garg


Use dataType: "json" to have jQuery parse the response as JSON. It will solve your problem.

like image 35
Codrutz Codrutz Avatar answered Oct 08 '22 15:10

Codrutz Codrutz