Avatar of Ivan Golubar
Ivan Golubar

asked on 

Processing of multiple variables echoed from php, as java scrip variables.

I attached illustration there is result of  code snippets below: string with user names (ivan4joni) and two users avatars .
I have two users : ivan4 and joni. As I have a while loop in php, I get names together as one string.

What would be the code for ajax to get a javascript variable as array [ ivan4 , joni]?
I don't need  users to be displayed as array on main page but as a array which will be then used in js functions.

  $.ajas x({
  method:"POST",
  url: '/wp-content/themes/net4/usersOnMainPageAjax.php',
  data:  {
      "querry2":1,
      "actualproject": whichProjectToSave
   },
   datatype: 'text',
    success: function(strdate){
   
  $('#usersWindowID > p').html(strdate);
     },
     error: function(error, txtStatus) {
      console.log(txtStatus);
      console.log('error');
    }
  });  

Open in new window


<?php
while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$partners_username=...............;
$partnersHTML=...............; 
echo $partners_username;
}
echo $partnersHTML;  
?>

Open in new window


In general I need to learn how to get two variables with ajax from php.
partners.png
PHPAJAXjQueryMySQL Server

Avatar of undefined
Last Comment
Ivan Golubar

8/22/2022 - Mon