报错代码
$.each(result,function (index,value) {
option.append("<option value='"+value.pid+"'>"+value.pname+"</option>")
})
修改后的代码
$.each(JSON.parse(result),function (index,value) {
option.append("<option value='"+value.pid+"'>"+value.pname+"</option>")
})
报错 web
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in [{"pid":1,"pname":"河南"},{"pid":2,"pname":"天津"},{"pid":3,"pname":"北京"}]
at r (jquery1.11.3.min.js:2)
at Function.each (jquery1.11.3.min.js:2)
at Object.success ((index):23)
at j (jquery1.11.3.min.js:2)
at Object.fireWith [as resolveWith] (jquery1.11.3.min.js:2)
at x (jquery1.11.3.min.js:5)
at XMLHttpRequest.b (jquery1.11.3.min.js:5)
原因
JSON字符串转换为JavaScript对象。要修复它,通过标准JSON.parse()或jQuery 的 $.parseJSON 将其转换为JavaScript对象。