1

I'm using wordress and i wrote a small script to compare posts. After i actived ssl it brokes my script.

I got this error in the developter consol.

Uncaught SyntaxError: Unexpected token <

jQuery.ajax({
        type: "POST",
        url: "<?php echo admin_url('admin-ajax.php') ?>",
        data: {
                action: 'compare',
                post_id: $(checkbox).val(),
                _ajax_nonce: '<?php echo wp_create_nonce('compare'); ?>'
            },
        success: function(html){
                html = $.parseJSON(html);
                console.log('success');
                $('#count').fadeIn(200);
                $('#count').html(html.length);
        },
        error: function(html){
                 console.log('error');
        }
});

1 Answers1

0

Change this line:

_ajax_nonce: '<?php echo wp_create_nonce('compare'); ?>'

to this:

_ajax_nonce: '<?php echo wp_create_nonce("compare"); ?>'
Zhafur
  • 1,626
  • 1
  • 13
  • 31
  • I change but after a click on the checkbox i got the same error message. Uncaught SyntaxError: Unexpected token < . Before the change to ssl everything works perfect. – user1898361 May 01 '16 at 16:15
  • If you call the AJAX from an HTTPS page TO a non secure HTTP, then it violates JavaScript's same-origin policy. http://stackoverflow.com/questions/6418620/jquery-ajax-and-ssl – Zhafur May 01 '16 at 17:01