【问题标题】:Different response from different browser来自不同浏览器的不同响应
【发布时间】:2017-06-25 18:52:03
【问题描述】:

我有一个 JSON API 插件。

有一个用于获取存储在数据库中的结果的查询,但它在不同的系统中给出了不同的响应。

我已经清除了浏览器 cookie 和缓存,但没有任何反应。 它一次又一次地存储设备ID,即使它已经存储了

我的功能如下:

public function store_device_id()
{
  global $wpdb;
  $device_id = $_REQUEST['device_id'];
  $device_type = $_REQUEST['device_type'];
  $table_name = $wpdb->prefix . 'ws_details';
  if(!empty($device_id) && !empty($device_type)) :
    $check = $wpdb->get_row( "SELECT * FROM $table_name WHERE device_id like '%".$device_id."%'" );
    if($check == '')
    {
        $result = $wpdb->insert( $table_name,array( 
                'time' => current_time( 'mysql' ), 
                'device_id' => $device_id,
                'device_type' => $device_type ), 
            array( '%s', '%s', '%s'));
        if ($result) 
        {
            $res = 'Device id saved.';
        } else {
            $res = 'Device id did not save.';
        }
    }
    else{
        $res = 'Device already register.';
    }
else :
    $res = 'Please enter device id & device type.';
endif;

nocache_headers();
$post = new JSON_API_Post();
$post = $res;
return array(
      'post' => $post
    );
}

这里有 Table 结构:

如果不存在则创建表 wp_ws_details ( id mediumint(9) NOT NULL AUTO_INCREMENT, device_id varchar(255) 整理 utf8mb4_unicode_ci 默认为空, device_type varchar(55) 整理 utf8mb4_unicode_ci NOT NULL DEFAULT '', time datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 唯一键 id (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT=1 ;

【问题讨论】:

  • 你在哪里使用这个 api?
  • 我在 android 中使用这个 api 来提供 web 服务
  • 在这个 where 子句中无法搜索设备 ID,所以我更改了登录名,但这是暂时的,我需要一个解决方案,请帮助我......
  • 为什么将 device_id 和 device_type 存储在不同的表中?您可以存储为 user_meta。
  • 看看wordpress.stackexchange.com/questions/189077/…你可以通过meta key获取用户详细信息

标签: wordpress


【解决方案1】:

如果您从不同的浏览器得到不同的响应,那么肯定存在缓存问题,而且是客户端问题。在不调用nocache_headers() 的情况下尝试您的功能,看看您会得到什么样的结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 2014-01-30
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    相关资源
    最近更新 更多