duanjigua5753 2016-02-21 12:03
浏览 104
已采纳

PHP ajax数据库:如何传递两个变量并在不同的选项中获取它们的数据?

(Re Post) i had going through this tutarial : PHP ajax database : how to pass two variables and get data of them in different div even one? ,but it seems not working,and i need to have 3 select works together.i choose first select option then using ajax to pass data for getting second and using the

                function showUser(strOther);

to get third data which is related to the first and second answer.all is running well but the third select which is:

               <select id="txtHint1">

doesnt show me any answer.here is my scripts:

                <script>
                   function showForum(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","getuser.php?q="+str,true);
                xmlhttp.send();
                }
                </script>

                <script>
                          function showUser(strOther) {
                 if(strOther==""){
             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","getuser.php?q1="+strOther,true);
              xmlhttp.send();
              }
            </script>

this is the select options which i get the ajax data:

                 <!-- this forum will be
                 choosed to pass data to get second 
                   select to filled up-->
                 <form>
                   <!-- first select-->
                  <select name="users" onchange="showForum(this.value)">
                 <option value="">All Orgs</option>
                 <option value="1">WebStatsProject</option>
                  <option value="2">mmu</option>

                  </select>
                  </form>

this select option will be filled by the first ajax request: All Forums the third not show any data,the other two working properly:

                            <!-- third select-->
                             <select id="txtHint1">
                            <option value="All Users">All Users</option>
                            </select>
  • 写回答

1条回答 默认 最新

  • duanmengsuo9302 2016-02-21 12:08
    关注

    Because you not define strOther
    try this

     function showUser(str,strOther){
    

    and pass strOther to this function

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分