With this chunk of JavaScript code, I add, fetch, and pass the ID of the post (like an array) to the function.php file.
  const nonRegister = document.querySelectorAll('.non-register')
  nonRegister.forEach(item=>{
  item.addEventListener('click', function(){
    let postNumber = item.getAttribute('data-post-id');
    let myFavoriteArray = JSON.parse(localStorage.getItem("favoriteItems") || "[]");
    let retrievedData = localStorage.getItem("favoriteItems");
    let retrievedDataArray = JSON.parse(retrievedData);
    if(retrievedDataArray !== null && retrievedDataArray.includes(postNumber)){
        alert('This model has already been added to favorites')
    }else{
        myFavoriteArray.push(postNumber);
        localStorage.setItem("favoriteItems", JSON.stringify(myFavoriteArray));
        let forConversion = JSON.parse(retrievedData);
        data = {
            'action': 'vicso_non_register',
            'forConversion': forConversion,
        }
            jQuery.ajax({
               type:'post',
               url: object_url.url,
               data: data,
               cache: false,
               success: function(data){
                 console.log(data)
               }
           });
         }
      })
   })
This is my code in a function.php file.
add_action( 'wp_ajax_nopriv_vicso_non_register', 'vicso_non_register' );
add_action( 'wp_ajax_vicso_non_register', 'vicso_non_register' );
function vicso_non_register(){
    $favorite_array    = $_POST['forConversion'];
    echo   $test = json_encode(array('favorite_array'=>$favorite_array));
    die;
}
But how do I get to the array that the function returns? I need a PHP array with these data on the fav_models.php for example.
If someone can suggest, please help.
 
                        
Sending data back as the ajax response in json format:
You could use wordpress
wp_send_json_successandwp_send_json_errorfunctions.And on the front end, you could
console.logthe response returned fromfunction.php.You could read more about these two functions on the documentation page.
Sending data to another page:
There are multiple ways to do it, you could
localize your scriptor I'd prefer to send it as aquery_var/query string.Then on the "fav_models.php" you could access that value by using this: