admin管理员组文章数量:1134246
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in "
This is the error I receive when I try to do a $.each
to this JSON object :
{"type":"Anuncio","textos":["Probando esto","$ 20150515"],"submit":"codParameters?___DDSESSIONID\u003d14EA4721A904D6DD71591156996E29F7%3A%2FMobilTest"}
I have also tried to do the same with stringify, but I receive the same error:
{\"type\":\"Anuncio\",\"textos\":[\"Probando esto\",\"$ 20150515\"],\"submit\":\"codParameters?___DDSESSIONID\\u003d06CBEC9D1A53616EFF703A8C71FBC2B4%3A%2FMobilTest\"}"
If I remove parameters ___DDSESSIONID\\u003d06CBEC9D1A53616EFF703A8C71FBC2B4%3A%2FMobilTest
from the object the $.each works fine.
Why might this be happening?
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in "
This is the error I receive when I try to do a $.each
to this JSON object :
{"type":"Anuncio","textos":["Probando esto","$ 20150515"],"submit":"codParameters?___DDSESSIONID\u003d14EA4721A904D6DD71591156996E29F7%3A%2FMobilTest"}
I have also tried to do the same with stringify, but I receive the same error:
{\"type\":\"Anuncio\",\"textos\":[\"Probando esto\",\"$ 20150515\"],\"submit\":\"codParameters?___DDSESSIONID\\u003d06CBEC9D1A53616EFF703A8C71FBC2B4%3A%2FMobilTest\"}"
If I remove parameters ___DDSESSIONID\\u003d06CBEC9D1A53616EFF703A8C71FBC2B4%3A%2FMobilTest
from the object the $.each works fine.
Why might this be happening?
Share Improve this question edited Jul 11, 2020 at 19:49 Usama Abdulrehman 1,0333 gold badges12 silver badges21 bronze badges asked May 15, 2015 at 22:07 Iván Alberto Fontalvo SalgadoIván Alberto Fontalvo Salgado 1,3692 gold badges9 silver badges3 bronze badges 1 |4 Answers
Reset to default 292The in
operator only works on objects. You are using it on a string. Make sure your value is an object before you using $.each
. In this specific case, you have to parse the JSON:
$.each(JSON.parse(myData), ...);
maybe you forget to add parameter dataType:'json' in your $.ajax
$.ajax({
type: "POST",
dataType: "json",
url: url,
data: { get_member: id },
success: function( response )
{
//some action here
},
error: function( error )
{
alert( error );
}
});
The only solution that worked for me and $.each
was definitely causing the error. so i used for loop
and it's not throwing error anymore.
Example code
$.ajax({
type: 'GET',
url: 'https://example.com/api',
data: { get_param: 'value' },
success: function (data) {
for (var i = 0; i < data.length; ++i) {
console.log(data[i].NameGerman);
}
}
});
this work for me
$.each(JSON.parse("[" + data + "]"))
$.each
only works on objects . if your data is an array you can change it like this
$data = (object)$array;
本文标签: javascriptUncaught TypeError Cannot use 39in39 operator to search for 39length39 inStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: Cannot use 'in' operator to search for 'length' in - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736809002a1953815.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
{}
text editor button, or indent every code line 4 spaces. – Sidd Commented May 15, 2015 at 22:09