First of all I want to tell you that I searched and didnot get any solution from stackoverflow's previous post for my problem.So I post my question here.
Following is data returned after echo json_encode($flterarr);
{"2":{"surname":"Winchester","mobile":"07898989898","license":"1234567890b"},"3":{"surname":"winchester","mobile":"07898989891","license":"1234567890bytfty"},"4":{"surname":"Test","mobile":"07678543210","license":"23frd"}}
Following is my ajax code
$.ajax(
{
type:"POST",
url: '../icabz/filterRefresh.php',
data: "filter_reset_surname="+filter_reset_surname+"&filter_reset_mobile="+filter_reset_mobile+"&filter_reset_reg_num="+filter_reset_reg_num+"&filter_reset_approval_status="+filter_reset_approval_status+"&filter_reset_logged_status="+filter_reset_logged_status,
success: function(data)
{
alert(data);
$.each( data, function(key,val) {
alert(val);
/*$.each( val, function( key1, val1 ) {
alert(val1.surname);
});*/
});
}
});
when I alert the raw data (without using dataType:"json" or $.parseJSON(data)
)returned from php page it is showing the data.But when I alert the returned data in the $.each()
function it is showing the word and showing following in the console.
TypeError: invalid 'in' operand obj
typeof length === "number" && length > 0 && ( length - 1 ) in obj;
Now if I trying to use dataType:"json" or $.parseJSON(data)
and alert the data.then it is showing [object Object].
I am using jQuery 1.11.1 version.
How can I fetch the data to get the surname?