title: Saving a JS Variable to Local Storage Passed from PHP
body: <p>When a build name is clicked the inner html is passed into a JavaScript variable loadDump then passed over to PHP.</p>
  
  <pre><code>    $.ajax({
    url:"http://custom-assembly.tcad.co.uk/wp-content/themes/custom-assembly/grp-enclosure/load.php",
    method: "post",
    data: { loadDump: JSON.stringify( loadDump )},
    success: function(res){
     var key_map_obj = '&lt;?php echo $key_map_loaded; ?&gt;';
     console.log(key_map_obj);
  
  
       var key_map_obj_string = key_map_obj;
  
       localStorage.setItem("key_map_obj_string", key_map_obj_string);
       console.log(localStorage);
    }
  })
  </code></pre>
  
  <p>Once this happens the php in load.php executes. The loadDump variable is used in a sql query to find the matching field.</p>
  
  <pre><code>$loadDump =   wp_unslash( $_POST['loadDump'] );
  
  
        $table_name= $wpdb-&gt;prefix. 'product_configurator';
          $DBP_results= $wpdb-&gt;get_results("SELECT * FROM $table_name WHERE keymap_key = $loadDump");
          $DBP_current_user = get_current_user_id();
  
  
       foreach($DBP_results as $DBP_cols){
          $user_id= $DBP_cols-&gt;user_id;
          $enclosure_type= $DBP_cols-&gt;enclosure_type;
          $keymap_key= json_decode($DBP_cols-&gt;keymap_key, true);
           $key_map_loaded=json_decode($DBP_cols-&gt;key_map, true);
  
            } 
  
  
  
            ?&gt;
  </code></pre>
  
  <p>How can i get $key_map_loaded to pass to the JavaScript and save in the local storage using Ajax.</p>