WordPress + plugin Really Simple SSL + json return

2019-07-14 11:45发布

So I have a Wordpress.org site with the plugin Really Simple SSL and I'd like to use ajax/JSON to update the database.

The thing is that, with the help of our friend @BadHorsie 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}?

1条回答
戒情不戒烟
2楼-- · 2019-07-14 12:16

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.

查看更多
登录 后发表回答