处理ajax返回变量

processing ajax return variable

本文关键字:变量 返回 ajax 处理      更新时间:2023-09-26

我有一个post request来处理一些表单和发送电子邮件。

我的代码是这样的:

$.post(url, data, function(r) {
processFormSubmitResult(r);
}, 'json');
function processFormSubmitResult(r) {
    console.log('text');
    console.log(r);
    if(r !== 'undefined') {
        $('#mistakesModal .modal-body ul.errors').empty();
        $.each(r, function(n, val) {
            if(n != 'email'){
                $('#mistakesModal .modal-body ul.errors').append('<li>השדה <span class="highlight">'+ translateFormToHebrew(n) +'</span> הינו שדה חובה</li>');
            } else {
                $('#mistakesModal .modal-body ul.errors').append('<li>'+ translateFormToHebrew(n) +' אינה תקנית</li>');
            }
        });
        $('#mistakesModal').modal('show');
    }
}

当我尝试console.log(r)时,它根本不起作用。它甚至没有console.log('text'),但它确实在处理错误…为什么呢?我只是想检查我的进程页面是否没有返回任何东西(在这种情况下,我希望r是其他东西,我试图通过close .log它来检测它会是什么)

提前感谢!

你应该看看jQuery "。方法文档

http://api.jquery.com/jquery.post/