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 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题