Javascript 通过ajax将多个php页面加载到phonegap

Javascript 通过ajax将多个php页面加载到phonegap,javascript,php,jquery,ajax,cordova,Javascript,Php,Jquery,Ajax,Cordova,我想通过ajax将多个php文件从外部数据库加载到phonegap中。 我曾尝试在第二个脚本中复制javascript并更改为txtHint1,但它无法工作。所以我想知道如何将多个外部文件加载到一个html中 <!-- database ---> <script> function showID(str) { if (str=="") {

我想通过ajax将多个php文件从外部数据库加载到phonegap中。 我曾尝试在第二个脚本中复制javascript并更改为txtHint1,但它无法工作。所以我想知道如何将多个外部文件加载到一个html中

<!-- database --->
      <script>
          function showID(str)
          {
              if (str=="")
              {
                  document.getElementById("txtHint").innerHTML="";
                  return;
              }
              if (window.XMLHttpRequest)
              {// code for IE7+, Firefox, Chrome, Opera, Safari
                  xmlhttp=new XMLHttpRequest();
              }
              else
              {// code for IE6, IE5
                  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
              xmlhttp.onreadystatechange=function()
              {
                  if (xmlhttp.readyState==4 && xmlhttp.status==200)
                  {
                      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                  }
              }
              xmlhttp.open("GET","http://database.com/about.php"+str, true);
              xmlhttp.send();
          }
      </script>

      <script>
          function showHISTORY(str)
          {
              if (str=="")
              {
                  document.getElementById("txtHint1").innerHTML="";
                  return;
              }
              if (window.XMLHttpRequest)
              {// code for IE7+, Firefox, Chrome, Opera, Safari
                  xmlhttp=new XMLHttpRequest();
              }
              else
              {// code for IE6, IE5
                  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
              xmlhttp.onreadystatechange=function()
              {
                  if (xmlhttp.readyState==4 && xmlhttp.status==200)
                  {
                      document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
                  }
              }
              xmlhttp.open("GET","http://database.com/history.php"+str, true);
              xmlhttp.send();
          }
      </script>


            <INPUT TYPE="BUTTON" name="id" style="background:url() no-repeat; border-style:none; width:0px; height:0px;" onload="showID()" value="">
                <div id="txtHint"></div>

            <INPUT TYPE="BUTTON" name="id" style="background:url() no-repeat; border-style:none; width:0px; height:0px;" onload="showHISTORY()" value="">
                <div id="txtHint1"></div>

您有两个名为showIDstr的函数

应该只有一个名为showIDstr的函数

所以有一个叫做showIDstr,还有一个叫做showidsomethinglesstr

然后将HTML更改为

<INPUT TYPE="BUTTON" name="id" style="background:url() 
   no-repeat; border-style:none; width:0px; height:0px;" 
   onload="showID()" value="">

<div id="txtHint"></div>

<INPUT TYPE="BUTTON" name="id" style="background:url() 
   no-repeat; border-style:none; width:0px; height:0px;" 
   onload="showIDSomethingElse()" value="">

您可以像这样尝试,您可以保留一个常见的ajax函数,并传递参数,获取相应的页面和更新

Javascript:

str="aboutus";
xmlhttp.open("GET","http://database.com/common.php?page="+str, true);
在common.php中

switch($_GET['page']){
     case "aboutus":
         include("aboutus.php");
     break;
    ....

  }

您考虑过使用jQuery吗?它使AJAX变得更容易,请尝试Krish R的解决方案。