JSON.parse不再在jquery 3中工作了吗?

时间:2017-05-30 19:08:47

标签: javascript jquery json ajax

我有一个js,目前正在使用jquery 2.1.1 ..然后我购买了一个jquery 3.1.1附带的模板。在我将代码迁移到模板后不久,js停止工作,特别是在JSON.parse。我已经搜索过,或许它已被弃用,但事实并非如此。这是代码:

var login = $("#loginnow").ladda();

$(document).ready(function() {

    login.click(function(event) {
        login.ladda('start');
        if (event.which == 13 && !event.shiftKey) {
            event.preventDefault();
            $("#frSendMessage").submit();
        }
    });

    $("#resetpass").click(function(event) {
        swal({
            title: "Forgot Password",
            text: "Enter your email to proceed with Password Reset",
            type: "input",
            showCancelButton: true,
            closeOnConfirm: false,
            showLoaderOnConfirm: true,
            inputPlaceholder: "email"
        },
        function(inputValue) {
            var v_email = verifyVar(encodeURIComponent(inputValue),'resetpass');
            displayVerify(v_email);
        });
    });
});

function loginNow(username,password) {
    var data = 'username='+value+'&password='+type;
    return $.ajax({
        type: 'POST',
        cache: false,
        data: data,
        url: '/pgadm/ajax/login.php'
    });
}

function verifyVar(value,type) {
    var data = 'value='+value+'&type='+type;
    return $.ajax({
        type: 'GET',
        cache: false,
        data: data,
        url: '/pgadm/ajax/resetpass.php'
    });
}

function displayVerify(ajaxCall) {
    ajaxCall.success(function(realData) {
        response = JSON.parse(realData);
        alert(response)
        if (!response.success) {
            var returnmsg = response.message;
            swal({
                title: "Error",
                text: returnmsg,
                type: "error",
                showCancelButton: false,
                confirmButtonText: "Back",
                closeOnConfirm: true
            });
        } else {
            swal({
                title: "On Its Way!",
                text: "Please check your email for further instruction on how to reset your Password",
                type: "success",
                showCancelButton: false,
                confirmButtonText: "Okay",
                closeOnConfirm: true
            });         
        }
    });
}

现在,正如您所看到的,函数displayVerify()在JSON.parse中断。 Firebug从服务器显示正常的json回复,但似乎没有被脚本解析。也许任何人以前都有这样的经历?

0 个答案:

没有答案