注册 登录
编程论坛 Python论坛

问一个有关python json的,求助呀!!!!!!

zhenxi123456 发布于 2012-10-30 11:20, 610 次点击
在 .js文件中的   ajax:
$.ajax({
            url: "/testname/",
            dataType: "json",
            type: "POST",
            data: { "aa": $("#uname").val() },
            success: function (data, textStatus,jqXHR) {
                if(data.data=="1"){
                    $("#usererror").html("您输入的用户已经占用!");
                    return false;
                }
                else if(data.data=="0"){
                    $('#usererror').html("可以使用!");
                    return false;
                }
                else
                {
                    alert('系统错误');
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {
                     alert('系统错误');
            }
        });
然后 在 view()函数中的 :
def testname(request):
    import json
    daa = request.POST.get("aa","")
    response=HttpResponse()
    ret ="2"
    if daa:
        try:
            Tuser2.objects.get(username=daa)
            ret="1"
        except:
            ret="0"
    response.write(json.dumps({"data": ret}))
    return response
我用 [url]http://127.0.0.1/testname/[/url] 测试的 ,在ie 和 火狐上 都可以返回 {"data": "2"},但是 回调函数中 ,ie 下 会报解析错误,但是 火狐下不会报错误。
谁能告诉我 为什么吗?  新手求助呀!!!!!
1 回复
#2
刘海earth2013-04-27 10:49
这么深奥了?刚注册完,学习!
1