ajax 返回数据 无法得到其属性的解决办法

当我们用ajax无法 得到其属性。正常情况下是:

<script type="text/javascript">
        function useAjax(sendUrl,name){

            $.ajax({
                type: "POST",
                url: sendUrl,
                data: { txtCode: $("#txtCode").val() },
                datatype: "json",
                timeout: 20000,
                success: function (json) {

      //无法使用的属性
                   alert(json.msg);
              
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                   
                }
            } );
        }
    </script>

如无法弹出其正常的属性值则需要用下面的方法解决:

<script type="text/javascript">
        function useAjax(sendUrl,name){

            $.ajax({
                type: "POST",
                url: sendUrl,
                data: { txtCode: $("#txtCode").val() },
                datatype: "json",
                timeout: 20000,
                success: function (json) {
                   //正常的使用的属性
                    json=JSON.decode(json);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(1);
                }
            } );
        }
    </script>

原文地址:https://www.cnblogs.com/WZH75171992/p/4121776.html