Hey guys I’m having a huge problem initializing jQuery on the backend of WordPress (widgets.php). I’m building a widget to display some select options that can only be accessed through SOAP, so I had to ajaxify it using admin-ajax.php. Everything works perfectly on the front-end but when it comes to the backend it breaks completely.

function widget_inject() {
echo "<script>
jQuery(document).ready(function($) {
var ajaxurl = '".admin_url('admin-ajax.php')."';
var list_target_id = 'list-target'; //first select list ID
var list_select_id = 'list-select'; //second select list ID
var initial_target_html = '<option value="">Please select category...</option>'; 
$('#'+list_select_id).change(function(e) {
var selectvalue = $(this).val();
$('#'+list_target_id).html('<option value="">Loading...</option>');
if (selectvalue == "") {
} else {
  $.ajax({url: ajaxurl,
  data: {
        action: 'parentcatajax1',
        parentCat: selectvalue
         success: function(output) {
      error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status + " "+ thrownError);

^This is what I’m trying. I’ve tried admin-init, admin-head, admin-footer none of them seem to work.
I’m at a stand still for a client & can’t figure out what to do.
Any suggestions? Thanks in advance!

Read more here: WordPress jQuery initialize widgets.php area


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , ,

Wordpress related questions and answers: