weixin_33712881 2016-10-01 22:06 采纳率: 0%
浏览 36

Ajax中的多个变量

I am trying to send 2 variable from my comobox but is does not work, it only works when I send 1 here is the ajax code:

$(document).ready(function()
{
$(".clase").hide();
$(".ruta").change(function(){
var id=$(".rutas").val();
var dataString = 'id='+ id;
$.ajax
({
type: "POST",
url: "asientos.php",
data: dataString,
cache: false,
success: function(html)
{
        $(".clase").show();
       $(".clase").change(function(){
      var id=$(".rutas").val();
      var cla=$(".clase").val();
      var dataString = 'id='+ id;
     var data = 'cla'+ cla;
$.ajax
  ({
          type: "POST",
          url: "asientos.php",
          data: dataString,data,
         cache: false,
         success: function(html)
{
        $(".asientos").html(html);
}
           });
        });
       }
    }); 
  });
});

Now here is my html only showing the combo part cause i have multiple components in the form

<label class="ruta">Rutas </label> <select name="rutas" id="rutas" class="rutas" >
<?php   include 'rutas.php';   ?>
</select>
<label class="clase">Clases </label><select name="clase" id="clase" class="clase">
<option value="A">Clase Ejecutiva</option>;
<option value="B">Clase Media</option>;
<option value="C">Clase Economico</option>;
</select>

In the first combo I am Retrieving data from database and the second combo I inputted the data, now i need that both values from each combo save to the variables I have in my Php file in order to fill the third combo.

  • 写回答

1条回答 默认 最新

  • 胖鸭 2016-10-01 22:15
    关注

    Note that you are using two ajax request here, you can only use second request and if you want to send two select box value by using ajax than this will not work:

    var dataString = 'id='+ id; 
    var data = 'cla'+ cla;
    

    You can just simply use:

    var dataString = 'id='+ id+'&cla='+cla;
    

    In ajax, no need to use like that:

    data: dataString,data,
    

    you can just use like that:

    data: dataString,
    
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵