WordPress +插件Really Simple SSL + json返回错误 [英] WordPress + plugin Really Simple SSL + json returning error

查看:130
本文介绍了WordPress +插件Really Simple SSL + json返回错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个带有插件Really Simple SSL的Wordpress.org网站,我想使用ajax/JSON来更新数据库.

问题是,在我们的朋友@BadHorsie 此处的帮助下,我能够确定该插件是在json_encode()值之后添加<!-- Really Simple SSL mixed content fixer active -->.

这是一个书签系统,因此只有一个按钮. 单击它会在数据库中添加一门课程,但是如果该课程已经存在,则会将其删除.

服务器端:

if($isFavorito) {
  echo json_encode(array("bookmark" => 1));
} else {
  echo json_encode(array("bookmark" => 0));
}

客户端:

<script>
  function addItemToUsersList(userId, type, itemId) {
    jQuery.ajax({
        'url': 'xxx', 
        'type': 'GET',
        'dataType': 'json', 
        'data': {userid: userId, type: type, itemid: itemId}, 
        'success': function(data)  {
            console.log('success');
        },
        'beforeSend': function() {
            console.log('beforeSending');
        },
        'error': function(jqXHR, status, error) {
            console.log(status);
            console.log(error);
            console.log(jqXHR.responseText);
        }
        });
  }
</script>

它记录:

beforeSending
parsererror
SyntaxError: Unexpected token < in JSON at position 14(…)
{"bookmark":0}<!-- Really Simple SSL mixed content fixer active -->

PHP运行正常,我已经在没有ajax/json的情况下对其进行了测试,并且它在MySQL数据库中添加/删除了我想要的东西.

我知道是造成此问题的插件,因为我已停用了该插件并且console.log()已记录success;

我该如何使其正常工作?正确的方法或hacky的方法都可以!

也许是将{"bookmark":0}<!-- Really Simple SSL mixed content fixer active -->修剪为{"bookmark":0}的一种方法?

解决方案

此处插件作者的回复:here, I was able to identify that the plugin is appending <!-- Really Simple SSL mixed content fixer active --> after the json_encode() value.

This is a bookmark system, so there is only 1 button. When it's clicked it adds a course in the database but if the course is already there, it removes it.

Server side:

if($isFavorito) {
  echo json_encode(array("bookmark" => 1));
} else {
  echo json_encode(array("bookmark" => 0));
}

Client side:

<script>
  function addItemToUsersList(userId, type, itemId) {
    jQuery.ajax({
        'url': 'xxx', 
        'type': 'GET',
        'dataType': 'json', 
        'data': {userid: userId, type: type, itemid: itemId}, 
        'success': function(data)  {
            console.log('success');
        },
        'beforeSend': function() {
            console.log('beforeSending');
        },
        'error': function(jqXHR, status, error) {
            console.log(status);
            console.log(error);
            console.log(jqXHR.responseText);
        }
        });
  }
</script>

And it logs:

beforeSending
parsererror
SyntaxError: Unexpected token < in JSON at position 14(…)
{"bookmark":0}<!-- Really Simple SSL mixed content fixer active -->

The PHP is working fine, I've tested it without the ajax/json and it adds/removes the thing I want in the MySQL database.

I know it's the plugins that's making this issue because I've deactivated the plugin and the console.log() logged success;

How may I make this to work properly? The right way or hacky way is fine!

Maybe a way to trim the {"bookmark":0}<!-- Really Simple SSL mixed content fixer active --> to {"bookmark":0}?

解决方案

Response from teh plugin author here: https://wordpress.org/support/topic/remove-really-simple-ssl-mixed-content-fixer-active-comment

In the class-frontend.php, search for the comment, and comment it out. That's all.

这篇关于WordPress +插件Really Simple SSL + json返回错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆