douxuanjie2692 2011-08-07 10:00
浏览 63
已采纳

Jquery 1.6.2不适用于数据类型:json

I'm making a signup form in which i've used following function for validate signup this function is called when a form is attempted to submit.

$.ajax({
    type: "POST",
    url: "view/ajax/php/checkcap.php",
    data: $('#capform').serialize(),
    dataType: "json",
    async: false,
    success: function(msg){
        alert(msg.txt);
        // other validations
    }
})

here alert is just for display response from checkcap.php file. it works perfectly with jquery 1.3.2 however i've upgraded the jquery 1.3.2 to 1.6.2. after using jquery 1.6.2, however function gets response from the php file (checked using firebug) but can't display the message (response from php file). how to make the code work with jquery 1.6.2 ?

  • 写回答

1条回答 默认 最新

  • dragon8002 2011-08-07 10:08
    关注

    make sure the json format is

    {
      "one": "Singular sensation",
      "two": "Beady little eyes",
      "three": "Little birds pitch by my doorstep"
    }
    

    http://api.jquery.com/jQuery.getJSON/

    You are missing double quotes on propertynames

    {"status":0,"txt":"a"}   ---correct
    {status:0,txt:"a"}       ---wrong
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导