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

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

    function GetXmlHttpObject()
    {
    if (window.XMLHttpRequest)
      {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      return new XMLHttpRequest();
      }
    if (window.ActiveXObject)
      {
      // code for IE6, IE5
      return new ActiveXObject("Microsoft.XMLHTTP");
      }
    return null;
    }
    
    function CallSomePHP(username, password)
    {
        xmlhttp=GetXmlHttpObject();
        if (xmlhttp==null)
        {
        alert ("Browser does not support HTTP Request");
        return;
        }
        var url="myPhp.php";
        url = url+"?username="+username+"&password="+password;
        xmlhttp.onreadystatechange=stateChanged;
        xmlhttp.open("GET",url,true);
        xmlhttp.send(null);
    }
    
    function stateChanged()
    {
        if (xmlhttp.readyState==4)
        {
            alert(xmlhttp.responseText); // this will alert "true";
        }
    }
    

    myphp.php

    
    

提交回复
热议问题