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({
  url: '/wp-content/themes/net4/usersOnMainPageAjax.php',
  data:  {
      "actualproject": whichProjectToSave
   datatype: 'text',
    success: function(strdate){
  $('#usersWindowID > p').html(strdate);
     error: function(error, txtStatus) {

Open in new window

while($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
echo $partners_username;
echo $partnersHTML;  

Open in new window

In general I need to learn how to get two variables with ajax from php.
Ivan GolubarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NerdsOfTechTechnology ScientistCommented:
From the syntax of your script, I presume you are using jQuery.

There are various ways to create the array. One way is by making the datatype: 'JSON' and have your PHP script return a JSON array.

Are you trying to have the PHP process and return a table instead? If so you would output HTML from the PHP script and make the ajax datatype: HTML
Ivan GolubarAuthor Commented:
This is working.

 success: function(strdate){
   var result1 = $.parseJSON(strdate);
  $('#usersWindowID > p').html(result1[0]);
 $('#usersWindowID > p').html(result1[1]);

Open in new window

echo json_encode(array($partnersHTML,$partners_username));

Open in new window

Now  I may  use each element of array separately.

newVariable= result1[1];

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NerdsOfTechTechnology ScientistCommented:
try this 1-liner:

echo json_encode(mysqli_fetch_assoc($query));

Open in new window

Ivan GolubarAuthor Commented:
I have found one example on the net code which helped me to make my own code.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.