I am using javascript and php to run an Ajax code. The result at the moment is undefined.
I am using localStorage to move the variable from the Ajax function because I cannot understand the use of a callback (I have followed numerous examples of using callbacks but none ever worked. I figured this solution might be the least complex.
Javascript:
$( document ).ready(function() {
   $('#submit-values').click(function(e){
        /************************************************************* SUBMIT */
        e.preventDefault();//Stop page reload on click
        $('#put-output-here').val(createParagraph());
   });
   function createParagraph(){
        createSentence();
        return localStorage.getItem('sentence');
   }
   function createSentence(){
        $.when(ajax1()).done(function(a1){
            localStorage.setItem('sentence', a1);
        })
   }
   function ajax1(){
       $.post("word-engine.php",
        {
        },
        function(data){
        });
   }
});
PHP:
<?php
    $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for($x = 0; $x < 10; $x++){
        $rand = rand(0,62);
        $randomString = $randomString.$chars[$rand];
    }
    echo $randomString;
?>
At the moment my result is undefined
 
     
     
    