2016-04-09 202 views
0
  <script type="text/javascript"> 
      $(document).ready(function(){ 
      $("#btn").click(function(){ 
       var from=$('input#searchfrom').val(); 
       var to=$('input#searchto').val(); 
       datastring="from="+from+"&to="+to; 
       $.ajax({ 
        type: "POST", 
        url: "measure.php", 
        data: dataString, 
        cache: false, 
        beforeSend: function(){ $("#btn").val('Connecting...').delay(6000);}, 
        success:function(response){ 
        $('#result').html(response);} 
       }); 

      }); 
      }); 
     </script> 

關注傳遞多個數據是保存值的元素在阿賈克斯

 From-<input id="searchfrom" type="text" size="50" placeholder="Enter a location" autocomplete="on"> 
        To-<input id="searchto" onblur="" type="text" size="50" placeholder="Enter a location" autocompete="on" > 
        <div id="result"></div> 
        <button type="button" id="btn" >Click</button> 

的Ajax功能不能通過數據mesaure頁,但它的正常工作,當一個參數傳遞,請幫我解決掉這個問題謝謝。

+0

做你''console.log'和from''to'的價值? – Drudge

回答

0

你可以象下面這樣: HTML內容:

<form id="searchForm"> 
<input id="searchfrom" name="searchfrom" type="text" size="50" placeholder="Enter a location" autocomplete="on"> 
        To-<input id="searchto" name="searchto" onblur="" type="text" size="50" placeholder="Enter a location" autocompete="on" > 
        <div id="result"></div> 
        <button type="button" id="btn" >Click</button> 
</form> 

JS代碼:

<script type="text/javascript"> 
     $(document).ready(function(){ 
     $("#btn").click(function(){ 
      datastring=$('#searchForm').serialize(); 
      $.ajax({ 
       type: "POST", 
       url: "measure.php", 
       data: dataString, 
       cache: false, 
       beforeSend: function(){ $("#btn").val('Connecting...').delay(6000);}, 
       success:function(response){ 
       $('#result').html(response);} 
      }); 

     }); 
     }); 
    </script> 
+0

OP代碼有什麼問題? – Drudge

+0

答覆其工作的問題... –

+0

請將此標記爲答案。 –