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

后端 未结 9 1606
孤街浪徒
孤街浪徒 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:30

    Use an asynchronous HTTP request in the JavaScript to load the output of the PHP script.

    For example, using the Prototype framework's Ajax.Request, say you have an HTML element with id="notice" and you want to update that based on the script's output (a simple "true" or "false" string).

    new Ajax.Request('/validate.php', {
      method: 'get',
      onSuccess: function(transport) {
        var notice = $('notice');
        if (transport.responseText == 'true')
          notice.update('Validation successful');
        else
          notice.update('Validation failed');
      }
    });
    

提交回复
热议问题