我试图运行一个ajax请求,将一些数据传递给我编写的函数。我返回响应,并尝试基于响应运行一些javascript,但它似乎运行不正常。不管回复是什么,它总是像“一切都是黑猩猩”一样运行
jQuery.ajax({
    type: \'POST\',
    url: ajaxurl,
    data: {
        action:      \'chimp_form\',
        form_action: \'validate_api_key\',
        api_key:     apiKey,
        data_center: dataCenter
    },
    success: function(validation_response) {
        // alert(validation_response);
        if(validation_response == "Everything\'s Chimpy!") {
            jQuery(\'.mailChimp_api_key_preloader\')
                .fadeOut(\'fast\', function() {
                    jQuery(\'.mailChimp_api_key_validation_message\')
                        .html(\'<img src="/images/mc-checkmark.png" alt=message > Valid API Key\')
                        .css("color", "green").fadeIn();
                });
        } else {
            // alert(response);
            jQuery(\'.mailChimp_api_key_preloader\')
                .fadeOut(\'fast\', function() {
                    jQuery(\'.mailChimp_api_key_validation_message\')
                        .html(\'<img src="/images/yikes-mc-error-icon.png" alt=message > Error: \'+validation_response+\'.\')
                        .css("color", "red").fadeIn();
                });                             
        };
    },
    error: function(response) {
        alert(\'There was an error processing your request...\'); 
    }
});
 我收到了ajax请求的回复,它说“一切都是黑猩猩!”,但我的条件没有运行。不管怎样,successfunction都会运行第二个条件。但我已经测试了响应,可以看到它与我的第一个条件语句相匹配。
为什么第一个没有运行?
最奇怪的是。。。我在localhost安装上开发了这个。当我将其转移到我的live站点时,这个ajax请求和成功回调不像在localhost上那样工作。我想不出为什么它在本地主机上的行为会与在实时站点上的行为有所不同。
This is the response that is coming back:错误:一切都是黑猩猩!。