weixin_33737774 2015-08-18 07:42 采纳率: 0%
浏览 22

发送两个值到ajax查询

I need to send two parameter to my javascript and get the parameters in the php file how I can do it ?

My html :

<form method="post" action="testButtonSup.php">
        <p>
           Veuillez choisir le service<br />
           <input type="radio" name="service" value="ncli" id="ncli" checked ="checked" /> <label for="ncli">Ncli</label>
           <input type="radio" name="service" value="fcli" id="fcli" /> <label for="fcli">Fcli</label>
        </p>
        <p>
            <label for="client">Veuillez choisir le fournisseur :</label><br />
               <select name="client" id="client" onchange="showUser(this.value, service)">
                    <?php 
                        // echo '<option value=""/></option>';
                        while ($donnees = $reponse->fetch())
                        {               
                            echo '<option value='.$donnees['refCustomer'].'>'.$donnees['legalCompanyName'].' </option>';
                            $idClient = $donnees['refCustomer'];                                
                            //$value = $donnees['refCustomer'];                     
                        }


                        $reponse->closeCursor();
                    ?>              
               </select>
            </p>
        <p>.....

I want to send to the function showUser(this.value, service) two parameters : the id of the select and the value of the radio button "service" whic is up

My function :

function showUser(str, service) {
        if (str == "") {
            document.getElementById("txtHint").innerHTML = "";
            return;
        } else { 
            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","getTableBuffer.php?q="+str+"&service="service,true);
            xmlhttp.send();
        }
    }

I tried like this but it doesn't work.

in my php file it didn't recognize the parameter.

It works with only the id of the select.

  • 写回答

2条回答 默认 最新

  • weixin_33675507 2015-08-18 07:50
    关注

    If you can use jQuery (which I recommend to handle ajax request) you can do it this way:

    function showUser(str, service) {
      if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
      } else { 
        $.ajax({
          url: 'getTableBuffer.php',
          type: 'GET',
          data: {q:str, service:service}
        }).done(function(response){
          // Code to execute once the call has been executed
          $('#txtHint').html(response.responseText);
        });
      }
    }
    
    评论

报告相同问题?