Javascript – Vue does not work with Ajax

I'm new to Vue and created a simple code:

var appCtrlUsuario = new Vue({
el: '#appCtrlUsuario',
data: {
    Nome: '',
    Email: '',
    Cond: '',
    Type: ({ id: 1, name: 'Morador' },
    { id: 2, name: 'Síndico - Rensponsável' },
    { id: 3, name: 'Administradora - Rensponsável' },
    { id: 4, name: 'Zelador – Rensponsável' },
    ),
    select: null
},
methods: {
    cadastrar: function () {
        var data = {
            "UserCondominio": this.Cond,
            "UserEmail": this.Email,
            "UserName": this.Nome,
            "UserType": this.select
        };

        $.ajax({
            url: "http://localhost:51541/Api.svc/cadastro-usuario",

            data: data,
            type: 'POST',
            success: function (result) {
                Swal.fire({
                    type: 'success',
                    title: 'Sucesso!',
                    text: 'Adicionado!'
                });
            },
            error: function (xhr, status, error) {
                Swal.fire({
                    type: 'error',
                    title: 'Erro!',
                    text: this.statusText
                });
            }
        });
    }
}
 });

When I click with the blank forms, a bug will be displayed in Ajax and the sweet alarm will be displayed. When I enter data, the page flashes and the models are reset and Ajax is never returned. Here is the HTML code:


  
  
      user Registration
      
      
      
      
      
  
  


      

user Registration

Does anyone know what is wrong?

paging – Paginated Ajax form with non-SQL data

With Drupal 8 I have created a form to load data from a web service with Ajax below the form. Now I'm trying to add pagination to the result, but the paginator was not loading, am I doing something wrong? I've tried to follow the guide from https://www.drupal.org/docs/7/creating-custom-modules/howtos/paging-non-sql-data, but it's for Drupal 7. Thanks in advance ,

Here is my code:

$ response contains an array of data from the web service.

$ total contains the record of the results

//number of records per page
$num_per_page = 3;
//get current page
$current_page = pager_default_initialize($total, $num_per_page);
$chunks = array_chunk($response, $num_per_page);
$current_page_items = $chunks($current_page);
foreach ($current_page_items as $i => $item) {
  $current_page_items($i) = array(
    '#theme' => 'ajax_search',
    '#item' => $item,
  );
}

// Generate the render array for our page
$render_array('page') = array (
  '#theme' => 'item_list',
  '#items' => $current_page_items,
);
// Calls Drupal standard pager theme and set 5 page links on pager
$render_array('pager') = array (
  '#theme' => 'pager',
  '#quantity' => 5,
);

$response = new AjaxResponse();
$response->addCommand(
  new HtmlCommand(
    '.result_message',
    $render_array)
  );
return $response;

Access to this Jquery / Ajax data in a PHP file, WordPress plugin

I have a JQuery UI sortable list associated with a different list. So far, my JavaScript can display the HTML IDs of both lists on the screen, but I'm having trouble figuring out how to redirect that data to a PHP file. Is wp_localize_script necessary for me? I have to show it to Ajaxurl plugins_url( 'my-ajax.php' ) this must go around admin_url( 'admin-ajax.php' )?
I'm trying to use this on an admin page I've created, not the frontend. This is extremely confusing.

This is how I try to queue JQuery in WordPress

add_action( 'admin_enqueue_scripts',array($this, 'admin_scripts' ));
function admin_scripts() {
  wp_register_script( 'admin-js', plugin_dir_url(__FILE__) . '/admin.js', array('jquery'), '', true);
  wp_localize_script( 'admin-js', 'dtAjax', array( 'ajaxurl' => plugins_url( 'my-ajax.php' , __FILE__)));
  wp_enqueue_script( 'admin-js' );
  wp_enqueue_script( 'jquery-ui-core' );
  wp_enqueue_script( 'jquery-ui-sortable' );            
  wp_register_style( 'digitable_jquery', '//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css', false, '1.0.0' );
  wp_enqueue_style( 'digitable_jquery' );
}

Here is the HTML

  • Item 1
  • Item 2
  • Item 3
  • Item 4
  • Item 5
  • Item 6
  • Item 7
  • Item 8
  • Item 9
  • Item 10

And the Javascript

jQuery(document).ready(function($){
    $(document).ready(function() {
        $('#sortable3, #sortable4').sortable({
            connectWith: ".filter-fields-list",
            stop: function (event, ui) {
                var data1 = $('#sortable3').sortable('toArray');
                var data2 = $('#sortable4').sortable('toArray');
                var sep = "/";
                var findata = (data1 + sep + data2);
                alert(findata);
                $.ajax({
                    data: findata,
                    type: 'POST',
                    url: dtAjax.ajaxurl,
                    failure: function(data) {
                        alert(("You suck" + dtAjax.ajaxurl));
                    },                  
                    success: function(data) {
                        alert(("You don't" + dtAjax.ajaxurl));
                    }
                });
            }
        }).disableSelection();
    });
});

What do I put in my-ajax.php to get the same data that gives me the warning in the query and print it on the screen for confirmation? Please help me, I have been programming for more than 7 days on this one thing lol (in the truest sense of the word 49 hours). All I need is to put that data into PHP, and I can figure out what to do with it afterwards.

Do not load Layout to Ajax Remove product in Minicart Magento 1

I create the ajaxDeleteProduct function, it's fine, but does not render the layout after the success. Please help me to fix it

My function

public function ajaxDeleteAction()
{
    $id = (int) $this->getRequest()->getParam('id');
    $result = array();
    if ($id) {
        try {
            $this->_getCart()->removeItem($id)->save();

            $result('qty') = $this->_getCart()->getSummaryQty();

            $this->loadLayout();
            $result('content') = $this->getLayout()->getBlock('minicart_content')->toHtml();
            $result('toplink') = $this->getLayout()->getBlock('top.links')->toHtml();
            $result('success') = 1;
            Mage::dispatchEvent('ajax_cart_remove_item_success', array('id' => $id));
        } catch (Exception $e) {
            $result('success') = 0;
        }
    }

    $this->getResponse()->setHeader('Content-type', 'application/json');
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}

8 – Paginated form with Ajax check box triggers: The specified # ajax callback is empty or unavailable

Using Drupal 8.7.7 I have a form that consists of a paginated user table.

Each user line contains a checkbox in the form to which an Ajax event is attached. Essentially, this allows me to save the selection in the user's session as they select users and switch to other pages.

The form works properly on the first page. However, if you switch to the second page, only the first selection works. Each selection made afterwards triggers the error:

Symfony Component HttpKernel Exception HttpException: The specified # ajax callback is empty or can not be called. in Drupal Core Form FormAjaxResponseBuilder-> buildResponse () (line 67 of /var/www/html/web/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php).

Here is the content of buildForm:

public function buildForm(array $form, FormStateInterface $form_state) {
    /** @var SymfonyComponentHttpFoundationSessionSession $session */
    $session = $this->requestStack->getCurrentRequest()->getSession();
    /** @var DrupalnodeEntityNode $node */
    $node = $this->requestStack->getCurrentRequest()->get('node');
    if (!$session->has($node->id().'_register_selection')) {
      $this->requestStack->getCurrentRequest()->getSession()->set($node->id().'_register_selection', ());
    } else {
      $selected = $session->get($node->id().'_register_selection');
    }

    $form('selected_users') = (
      '#type' => 'container',
      '#attributes' => ('id' => 'selected-users'),
    );

    $users = $form_state->getValue('user_list');
    if (!empty($users)) {
      foreach ($users as $user) {
        if ($user('check') == TRUE) {
          $selected($user('uid')) = $user('uid');
        } elseif (array_key_exists($user('uid'), $users)) {
            unset($selected($user('uid')));
        }
        $session->set($node->id() . '_register_selection', $selected);
      }
    }

    if (!empty($selected)) {
      foreach ($selected as $item) {
        $form('selected_users')($item)('user') = (
          '#type' => 'item',
          '#markup' => t('user: @user', ('@user' => $item)),
          '#weight' => '0',
        );
      }
    }

    $header = (
      ('data' => $form('user_list')('check_all') = (
          '#type' => 'checkbox',
          '#title' => t('Select all'),
          '#return_value' => TRUE,
          '#wrapper_attributes' => (
            'class' =>('align-middle', 'm-0')
          )
        ),
        'class'=> ('py-4')
      ),
      'uid' => ('data' => t('UID'), 'class'=> ('align-middle', 'py-4')),
      'username' => ('data' => t('Username'), 'class'=> ('align-middle', 'py-4')),
      'sits_id' => ('data' => t('SITS ID'), 'class'=> ('align-middle', 'py-4')),
      'name' => ('data' => t('Name'), 'class'=> ('align-middle', 'py-4')),
      'mail' => ('data' => t('Email'), 'class'=> ('align-middle', 'py-4')),
      'college' => ('data' => t('College'), 'class'=> ('align-middle', 'py-4')),
      'programme' => ('data' => t('Programme'), 'class'=> ('align-middle', 'py-4')),
      'course' => ('data' => t('Course'), 'class'=> ('align-middle', 'py-4')),
      'year' => ('data' => t('Year'), 'class'=> ('align-middle', 'py-4')),
    );

    $form('user_list') = (
      '#type' => 'table',
      '#header' => $header,
      '#empty' => t('No users found with the selected filters.'),
      '#prefix' => "
", '#suffix' => "
", '#attributes' => ( 'class' => ('table-sm'), 'style' => 'font-size: .85rem', ) ); $query = $this->database->select('users_field_data', 'ufd'); $query->leftJoin('profile', 'profile', 'profile.uid = ufd.uid'); $query->leftJoin('profile__field_prof_sits_id', 'sitsid', 'sitsid.entity_id = profile.profile_id'); $query->leftJoin('profile__field_prof_first_name', 'fname', 'fname.entity_id = profile.profile_id'); $query->leftJoin('profile__field_prof_last_name', 'lname', 'lname.entity_id = profile.profile_id'); $query->leftJoin('profile__field_prof_college', 'college', 'college.entity_id = profile.profile_id'); $query->leftJoin('profile__field_prof_programme', 'programme', 'programme.entity_id = profile.profile_id'); $query->leftJoin('profile__field_prof_course', 'course', 'course.entity_id = profile.profile_id'); $query->leftJoin('profile__field_prof_sits_year', 'year', 'year.entity_id = profile.profile_id'); $query->fields('ufd', ('uid','name', 'mail')); $query->addField('sitsid', 'field_prof_sits_id_value', 'sits_id'); $query->addField('fname', 'field_prof_first_name_value', 'first_name'); $query->addField('lname', 'field_prof_last_name_value', 'last_name'); $query->addField('college', 'field_prof_college_target_id', 'college_gid'); $query->addField('programme', 'field_prof_programme_target_id', 'programme_gid'); $query->addField('course', 'field_prof_course_target_id', 'course_gid'); $query->addField('year', 'field_prof_sits_year_value', 'year'); $query->extend('DrupalCoreDatabaseQueryTableSortExtender')->orderByHeader($header); $pager = $query->extend('DrupalCoreDatabaseQueryPagerSelectExtender')->limit(10); $results = $pager->execute()->fetchAll(); if ($results) { foreach ($results as $data) { $form('user_list')($data->uid)('check') = ( '#type' => 'checkbox', '#ajax' => ( 'callback' => '::processUser', 'wrapper' => 'selected-users', ), '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0', 'p-0', 'text-align-center') ), '#attributes' => ( 'class' => ('m-0'), 'style' => 'position:relative;', ), '#default_value' => isset($selected($data->uid)) ? TRUE : FALSE, ); $form('user_list')($data->uid)('uid') = ( '#type' => 'item', '#markup' => $data->uid, '#value' => $data->uid, '#weight' => '0', '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0') ) ); $form('user_list')($data->uid)('username') = ( '#type' => 'item', '#markup' => $data->name, '#value' => $data->name, '#weight' => '0', '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0') ) ); $form('user_list')($data->uid)('sits_id') = ( '#type' => 'item', '#markup' => $data->sits_id, '#value' => $data->sits_id, '#weight' => '0', '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0') ) ); $form('user_list')($data->uid)('name') = ( '#type' => 'item', '#markup' => $data->first_name . ' ' . $data->last_name, '#value' => $data->first_name . ' ' . $data->last_name, '#weight' => '0', '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0') ) ); $form('user_list')($data->uid)('mail') = ( '#type' => 'item', '#markup' => $data->mail, '#value' => $data->mail, '#weight' => '0', '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0') ) ); $form('user_list')($data->uid)('college') = ( '#type' => 'item', '#markup' => $data->college_gid, '#value' => $data->college_gid, '#weight' => '0', '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0') ) ); $form('user_list')($data->uid)('programme') = ( '#type' => 'item', '#markup' => $data->programme_gid, '#value' => $data->programme_gid, '#weight' => '0', '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0') ) ); $form('user_list')($data->uid)('course') = ( '#type' => 'item', '#markup' => $data->course_gid, '#value' => $data->course_gid, '#weight' => '0', '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0') ) ); $form('user_list')($data->uid)('year') = ( '#type' => 'item', '#markup' => $data->year, '#value' => $data->year, '#weight' => '0', '#wrapper_attributes' => ( 'class' => ('align-middle', 'm-0') ) ); } } $form('actions') = ( '#type' => 'actions', '#attributes' => ( 'class' => ('mb-4', 'd-flex', 'justify-content-center') ) ); $form('actions')('submit') = ( '#type' => 'submit', '#value' => $this->t('Register'), '#name' => 'update', ); $form('pager') = ('#type' => 'pager'); return $form; } }

And the processUser callback:

  public function processUser(array &$form, FormStateInterface $form_state) {
    return $form('selected_users');
  }

This seems to work correctly without pagination. However, if you enable pagination, it will be interrupted. Has anyone experienced that?

woocommerce – AJAX content that only appears when the customizer is open

This is probably a special WooCommerce issue, but it still applies here. I am using the AJAX add-to-cart feature. So if you click on the "Add to Cart" item should be put in the cart (this part works). You will also see a message confirming that the product has been added to the shopping cart (This part is not) while the page is not being reloaded.

The strange thing is that the "X has been added to your shopping cart" is only displayed when I'm in the customizer, not when I look at the page normally. Even looking at the page, I can see that the container for the message exists but contains no content, so it does not just hide. Has anyone ever seen this, or are there troubleshooting steps that I should take to find out why it behaves properly only when the customizer is open?

Plugins – Alerts on the site regarding Ajax portfolio / Lib / Gravity fields

In the hope that someone can help, I have a website that displays the following alerts, and I'm not sure what causes this issue and how it can be fixed.

Warning: mysql_real_escape_string(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /websites/ke/wp-content/plugins/ajax-portfolio/lib/gravity-fields/classes/GF_Datastore_Termsmeta.php on line 237

Warning: mysql_real_escape_string(): A link to the server could not be established in /websites/ke/wp-content/plugins/ajax-portfolio/lib/gravity-fields/classes/GF_Datastore_Termsmeta.php on line 237

Warning: mysql_real_escape_string(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /websites/ke/wp-content/plugins/ajax-portfolio/lib/gravity-fields/classes/GF_Datastore_Termsmeta.php on line 240

Warning: mysql_real_escape_string(): A link to the server could not be established in /websites/ke/wp-content/plugins/ajax-portfolio/lib/gravity-fields/classes/GF_Datastore_Termsmeta.php on line 240

I am not sure if this is a problem with the webhosting connection.

ajax – The WordPress Heartbeat API can not parse data

I had a working heartbeat connection that updated a user's personal (custom) options that I created. The heartbeat switches from the front-end dashboard to the screen, which reflects the profile in a different location.

Now, however, a parsing error is displayed in the passed JSON file, and the error can not be output for debugging for my entire life. I've recently updated to the latest jQuery and WordPress versions, but even if I reset to the older version, the errors will still be displayed.

This is my frontend for the user:

// AJAX form




// the heartbeat
$(document).ready( function() {

    $(document).on( "heartbeat-send", function( e, data ) {
        data.mb_user_id = $('input(name="mb_user_id")').val();
    });

    $(document).on( "heartbeat-tick", function( e, data ) {
        data.mb_user_location && $("input#mb_user_location" + data.location ).prop( "checked","checked" );
    });

    $(document).on( "heartbeat-error", function( e, jqXHR, textStatus, error ) {
        console.log( textStatus + ' ----------- ' + error );            
    })
});

// php
function mb_heartbeat_received( $response, $data ) {

    if( empty($data('mb_user_id')) || !is_numeric($data('mb_user_id')) ) {
        return $response;
    }

    $mb_userid = absint($data('mb_user_id'));

    $response('mb_user_location') = get_user_meta( $mb_userid, 'mb_user_location_current', true );

    return $response;
}

I get the error:

SyntaxError: JSON Parse error: Unexpected identifier "SyntaxError"