0

I am working on a plugin but I am getting this error Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0 when adding elements in gravity forms Version 2.5.10.1 only when my plugin is calling a class. This error also occurs when When interacting with different tools in WordPress (kind of all over) but again, only when my plugin is calling a class. But I receive no errors when I do this with functions as opposed to OOP.

Using XAMMP 7.4.23-0

macOS Big Sur: Version 11.6

Plugin Code


/*
Plugin Name: Testing plugin

Description: filler
Version: 1.0
Author: me
Author URI: http://www.google.com
License: GPLv2 or later
Text Domain: plugins testing 
*/

if ( ! defined ( 'ABSPATH')) exit; // Exit if accessed directly


define( 'AGFR__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );



class testing_reporting{
    public function init() {
        $this->console_log("Initiating AgfReport class.");
        $this->console_log("AgfReport Short Code initiated.");          
    }
    private function console_log($output = null, $with_script_tags = true) {
        if($output != null){
            $js_code = 'console.log(' . json_encode($output, JSON_HEX_TAG) . ');';
            if ($with_script_tags) {
                $js_code = '<script>' . $js_code . '</script>';
            }
            echo $js_code;
        }
    }
}

$new_class = new testing_reporting();
$new_class->init();
PlutoTom
  • 28
  • 4
  • 1
    Your script expects JSON, but is getting HTML. Use your browser inspector to see what the server is returning (likely some kind of error message.) – miken32 Nov 26 '21 at 20:05
  • When adding `` I received the following error. I guess my main concern is why do I get this error only when calling a class in my plugin? `admin.php?page=gf_edit_forms&id=1:1 Uncaught ReferenceError: xhr is not defined at admin.php?page=gf_edit_forms&id=1:1 (anonymous) @ admin.php?page=gf_edit_forms&id=1:1` – PlutoTom Nov 27 '21 at 16:27

0 Answers0