Search code examples
javascriptphpjqueryajaxadobe-edge

ajax importing json content from php to edge animate


I am working on this project in edge animate for a school assignment. I have a database on my school webspace and I need to import some data from that database into my edge animate project.

I've been looking on the internet how to do this and these pictures show what I have so far. It still has a javascript error, but I can't figure out what. If I could just get that javascript error sorted, I can add code do some things with the array.

I collect the data from the database in a php-array and I want to save it in an array in javascript so I can display anything from inside that array on different places I want to.

edge animate code

php code


Solution

  • thats because $.ajax is a jquery function, therefore you have to import this libary.

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script>
        function Load()
        {
            console.log('start ajax query...');
    
            var delivery;
    
            $.ajax({
                method: "POST",
                url: "test.php",
                data: { foo: "bar" }
            })
            .done(function( data ) {
                delivery=data;
                console.log(data);
                console.log('...all fine');
            });
        }
    
    $( document ).ready(function() {
        console.log( "firing load function..." );
        Load();
    });
    
    </script>
    

    PHP Script

    dont modify the header, simply echo the return of json_encode().

    <?php
    /**
     * FILE test.php
     */
        echo json_encode(array('foo'=>'bar'));
    ?>