• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

清宇诺诺

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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>

posted on 2014-11-25 19:37  清宇诺诺  阅读(594)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3