weixin_33737774 2015-12-02 04:11 采纳率: 0%
浏览 11

传递一个jQuery变量

i'm having trouble with the following jquery code

$this->registerJs(
    'jQuery(document).ready(function($){

    $(".member").on("change",function(){
        var id = $(this).attr("id");
        // alert(id);
        var n = $(this).val();
        // alert(n);
        $.post("'.\Yii::$app->getUrlManager()->createUrl(['death/stl_set_relation','id'=>'+id'])
            .'&name="+id) 


        });

      });'
);

i want the ajax link to be like this http://192.168.1.4/~user/church/backend/web/death/stl_set_relation?id=20&name=1

but with my code i'm not able to pass value of id correctly. what my code creates is the following url

http://192.168.1.4/~user/church/backend/web/death/stl_set_relation?id=%2Bid&name=20

i also tried like this

$.post("'.\Yii::$app->getUrlManager()->createUrl(['death/stl_set_relation','id'=>'"+id"'])
                .'&name="+id) 

but it didn't give me the desired result

how can i pass the value of id correctly?

  • 写回答

4条回答 默认 最新

  • weixin_33725270 2015-12-02 04:55
    关注

    try like this may be it will work..

    $.post("'.\Yii::$app->getUrlManager()->createUrl(['death/stl_set_relation','id'=>'"+id+"'])
            .'&name="+n);
    
    评论

报告相同问题?

悬赏问题

  • ¥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键失灵