我有一个文本字段和一个输入类型提交。当我点击提交按钮时,我应该得到一个与输入字段相关的网址。但我得到了Uncaught TypeError: undefined is not a function
。这是我的代码更好地解释了:
<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>
答案 0 :(得分:2)
在javascript中,您使用+
连接字符串,而不是.
所以:
var url_to_go =
"<?php echo BASE_URL; ?>/ads/search/" + $('#thisiswhatineed').val();
答案 1 :(得分:2)
使用+
运算符代替.
来连接JavaScript中的两个字符串。
而不是
var url_to_go = "<?php echo BASE_URL; ?>/ads/search/" . $('#thisiswhatineed').val();
使用
var url_to_go = "<?php echo BASE_URL; ?>/ads/search/" + $('#thisiswhatineed').val();
答案 2 :(得分:2)
在Javascript中,您使用加号进行连接。
var url_to_go = "<?php echo BASE_URL; ?>/ads/search/" + $('#thisiswhatineed').val();