K
K
Konstantin Lavrovsky2020-04-27 15:17:54
PHP
Konstantin Lavrovsky, 2020-04-27 15:17:54

How to pass two data parameters to ajax.done?

Good afternoon, I have ajax sends search data and outputs with

$users = $wpdb->get_results( "SELECT * FROM table WHERE ".$user_filter." ORDER BY ID DESC" );
  foreach ($users as $u ){
    if ($u->user_status == 1){
      $status = '<span class="profile_status">VIP</span>';
    }else{
      $status = '';
    }
    if($u->user_customid == ''){
      $userID = $u->ID;
    }else{
      $userID = $u->user_customid;
    }
    echo '
    <div class="profile_card">
      <div class="profile_avatar">
        <div class="img_wrapper">
          <a href="pagedonor?id='.$u->ID.'"><img src="'.$u->user_microavatar.'" alt="userAvatar"></a>
        </div>'.$status.'
      </div>
      <div class="profile_info">
        <p>Donor ID: <span>'.$userID.'</span></p>
        <p>Age: <span>'.$u->user_age.'</span></p>
      </div>
    </div>
    ';
  }

ajax processing
$('#filters').submit(function(event) {
      event.preventDefault();
      var filterData = $(this).serialize();
      $.ajax({
        url: 'filter.php',
        type: 'POST',
        data: filterData,
      })
      .done(function(data) {
        $('.profiles_wrapper').html(data);
        var _hrefs = '#profiles';
        $("html, body").animate({scrollTop: $(_hrefs).offset().top+"px"});
      })
      .fail(function() {
        console.log("error");
      })
      .always(function() {
        console.log("complete");
      });
    });

I need to pass another array with filters back, which is collected in the $user_filter handler depending on the choice of the necessary filters, and pass it to the get link to the page.
How can I implement this? I did not work with Json before, I tried now, but nothing comes out.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadym Masiuk, 2020-04-27
@s1mypj

In this case, you can’t do without json, since AJAX receives a string in response one way or another, and passing two strings will not work without a crutch (Well, there’s like a separator, etc.). The bottom line is this: on the PHP side you respond with a json string, and on the client you parse the string and process it as needed ...
But, something tells me that you partially want to receive the same data from the server that you send to the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question