zoukankan      html  css  js  c++  java
  • jquery的ajax方法在无返回值时的返回值类型设定

     

    2013-12-07 19:15:29|  分类: Web前端 |  标签:html  |举报|字号 订阅

     
     

    $.ajax({

           type: "post",

           url: "index.php",

           data: "id="+uid,

           dataType:"json",

           success : function(){

                  alert(1);

           },

           error: function(){

                  alert(0);

           }

    });

     

    jquery的ajax方法中,传递参数后,回调判断有success 和 error两种情况。

    有时,在不需要返回值的情况下,扔按模板格式,设置了dataType:"json",参数;这时候,ajax传值正确时,出现200返回成功状态下报错的特殊情况。

     

    以前没注意到ajax方法的返回值数据类型的设置问题。在没有回传参数时,一般无需设置返回值的数据类型。如果设置出错,一般都报错。这时候,直接取消dataType:"json",

    参数即可。

    无返回值的ajax方法正确模板:

    $.ajax({

           type: "post",

           url: "index.php",

           data: "id="+uid,

           success : function(){

                  alert(1);

           },

           error: function(){

                  alert(0);

           }

    });

     

    同理,再次推测;在回调参数数据格式不为 json的时候,同样也不能设置dataType:"json",避免类似问题产生。

    转自http://wu110cheng.blog.163.com/blog/static/133349654201311771529542/

  • 相关阅读:
    Stepping Number
    Replace String
    String Permutation
    Clock Angle
    Keypad Permutation
    Replace Words
    1、奉加微 PHY6202 Get started
    Python3 修改二进制文件
    Google Fast Pair
    python 校验 BLE resolvable private address
  • 原文地址:https://www.cnblogs.com/liziqiang/p/4080406.html
Copyright © 2011-2022 走看看