weixin_33675507 2017-09-27 15:56 采纳率: 0%
浏览 26

访问Javascript变量

i have this code :

$('button#monbtn').click(function() {
  var username = $('#username').val();
  var msg = $('#msg').val();

  var url = "{{ path('ajax_subcategories', {'username': username,'msg':msg})|escape('js') }}";
}

I get the username and msg from inputs, and i want to add them to the url, but i get an error saying that variable username doesn't exist.

  • 写回答

2条回答 默认 最新

  • weixin_33719619 2017-09-27 15:58
    关注

    You're not writing the username variable, you're literally writing the word username into the string. Hence the template parser (I guess) says that itself does not know this var.

    In JS, you have to print vars like this:

    var url = "{{ path('ajax_subcategories', {'username': "+username+",'msg':"+msg+"})|escape('js') }}";
    
    评论

报告相同问题?

悬赏问题

  • ¥25 LT码在高斯信道下的误码率仿真
  • ¥45 渲染完成之后将物体的材质贴图改变,自动化进行这个操作
  • ¥15 yolov5目标检测并显示目标出现的时间或视频帧
  • ¥15 电视版的优酷可以设置电影连续播放吗?
  • ¥50 复现论文;matlab代码编写
  • ¥30 echarts 3d地图怎么实现一进来页面散点数据和卡片一起轮播
  • ¥15 数字图像的降噪滤波增强
  • ¥15 心碎了,为啥我的神经网络训练的时候第二个批次反向传播会报错呀,第一个批次都没有问题
  • ¥15 MSR2680-XS路由器频繁卡顿问题
  • ¥15 VB6可以成功读取的文件,用C#读不了