Poll, Quiz not working in ajax.
-
Hello. We really like your product and we use it.
But when developing a new functional, we are faced with a problem and we hope that you will help us.Now we are using the latest version of the plug-in Poll, Survey, Quiz, Slideshow, Form & Story Article (Version 19.3.5).
All works well when we add the widget to the sidebar, but when we try to load the sidebar with the widget using AJAX, we get a 500 error.For a better understanding, let’s take a sample code that can be run on any standard theme:
PHP:
add_action('widgets_init', function(){ register_sidebar(array( 'name' => 'test-sidebar', 'id' => 'test-sidebar' )); }); add_action('wp_ajax_load_sidebar', 'load_sidebar_call'); add_action('wp_ajax_nopriv_load_sidebar', 'load_sidebar_call'); function load_sidebar_call(){ ob_start(); dynamic_sidebar('test-sidebar'); $data = ob_get_contents(); ob_end_clean(); echo json_encode( array('data' => $data) ); die(); }
jQuery:
jQuery.ajax({ url: location.origin + '/wp-admin/admin-ajax.php', type: 'POST', dataType: 'json', data: { action: 'load_sidebar', }, success: ( response ) => { console.log(response); } });
In the Apperance-> Widgets section, a test sidebar appears, into which you can add widgets.
If you add any standard or third-party widgets to it and then execute jQuery code in the browser console on the home page of the site, console.log will show us the contents of the sidebar.
If we add Opinion Stage Sidebar Widget to this sidebar then there will be a 500 error.
In this case, the php error log will display information about the cause of the error:
PHP Fatal error: Uncaught Error: Call to undefined function opinionstage_widget_placement ()
Could you help us with this?
Thanks
- The topic ‘Poll, Quiz not working in ajax.’ is closed to new replies.