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

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题