尝试在程序去访问远程的Web API,它在运行时,出现异常: 

TypeError: invalid 'in' operand obj


TypeError: invalid 'in' operand obj


由于从服务器返回的数据是json。
当我们需要得到这些数据时,还得需要Parse。
因此我们把代码稍微修改一下:
TypeError: invalid 'in' operand obj
 
$(function () {
            $.ajax({
                type: "GET",
                url: "http://localhost:9001/api/size",                
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (data) { 
                    data = $.parseJSON(data);
                    $.each(data, function (index, item) {
                        //...
                    });                  

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(errorThrown);
                }
            });
        });
Source Code

 



相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2021-10-04
  • 2021-08-29
  • 2021-07-28
  • 2022-12-23
猜你喜欢
  • 2021-09-26
  • 2022-12-23
  • 2021-12-26
  • 2021-09-10
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案