【问题标题】:Getting 502 error in wordpress在 wordpress 中出现 502 错误
【发布时间】:2015-06-28 06:37:46
【问题描述】:

在我的 wordpress 网站中,我必须在 javascript 函数的一段时间后调用 PHP 函数。 有时它工作正常。但有时会抛出 502 错误代码。 你能解释一下为什么会抛出这种类型的错误吗?我该如何解决这个错误? 我的javascript函数:

function set_online_user(){

clearInterval(setOnlineUser);
if(setUserOnline == true)
{
    setUserOnline = false;
    jQuery.ajax({
            type: 'POST',
            url: WQChat.ajaxurl,
            data: ({action : 'my_action_set_user_online'}),
            success: function(response) {
                    print_in_console("set_online_user"+response);
                    setUserOnline = true;
                    setOnlineUser = setInterval(function(){ set_online_user(); }, 1000);
                },
            statusCode: {
                502: function (error) {
                    console.log(error);
                }
            }
        });
}
}
var setOnlineUser = setInterval(function(){ set_online_user(); }, 1000);

而我的 PHP 函数是:

function my_action_set_user_online()
{
global $wpdb;
$currentUserId = get_current_user_id();
$time = current_time( $type = 'timestamp', $gmt = 1 );
if($currentUserId)
{
    update_user_meta( $currentUserId, 'last_login_on', $time);  
}
if (time_nanosleep(0, 50000000) === true) {
    echo $currentUserId;
}
die();
}

提前谢谢..

【问题讨论】:

    标签: php jquery ajax wordpress error-handling


    【解决方案1】:

    如果ajaxurl 位于不同的域中,您需要使用cross-domain ajax

    【讨论】:

    • ajaxurl 在同一个域中
    猜你喜欢
    • 2017-06-25
    • 1970-01-01
    • 2021-03-22
    • 2016-02-16
    • 2012-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多