drlhsfqoa350437979 2014-07-20 01:38
浏览 24
已采纳

为什么连接两个字符串会出错?

I have a text field and an input type submit. When I click on the submit button I should get a url related to the input field. But I am getting Uncaught TypeError: undefined is not a function. Here's my code that explains more better:

<script>

    $(document).ready(function(e) {

        $('#search_btn').click(function() {
            console.log($('#thisiswhatineed').val()); // this is working perfectly
            console.log("<?php echo BASE_URL; ?>/ads/search/"); // this is also working perfectly
            var url_to_go = "<?php echo BASE_URL; ?>/ads/search/" . $('#thisiswhatineed').val(); 
            console.log(url_to_go); // this is not working and giving me the error mentioned above
        });

    });

</script>
  • 写回答

3条回答 默认 最新

  • douyin8813 2014-07-20 01:39
    关注

    In javascript, you concatenate strings with +, not .

    So:

    var url_to_go = 
       "<?php echo BASE_URL; ?>/ads/search/" + $('#thisiswhatineed').val(); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序