Call php from javascript and return an array from php to Javascript function

后端 未结 9 1614
孤街浪徒
孤街浪徒 2020-12-03 13:22

I want to write a function in javascript which will call the Getfilename.php and Get the $filesArray that is return in javascript.

GetFilenme.php is another file and

9条回答
  •  情歌与酒
    2020-12-03 13:27

    This is assuming you download and include the jQuery javascript library:

    $(function() {
        $.get('getfilename.php', { dir : 'path/to/dir' }, function(data) {
            // you should now have a json encoded PHP array
            $.each(data, function(key, val) {
                alert('index ' + key + ' points to file ' + val);
            });
        }, 'json');
    });
    

    This should be your PHP (although very insecure):

    
    

提交回复
热议问题