如何解决此错误,我在php视图文件上使用ajax请求。
我的代码在这里。
$( "body" ).on ("keypress", "#comment", function( event ) {
if(event.which == 13)
$.ajax({
type: "post",
url: <?php echo 'localhot/mcportal/public/post/comment/196675710685996' ?>,
data: {},
success: function (response) {
alert( 'Comment posted' );
}
});
}
});
您尚未为 if 条件添加左大括号
你必须
在你的if语句中添加开头{
,并在你的url
周围加上引号。否则,你的网址将不是Javascript中的字符串。
$( "body" ).on ("keypress", "#comment", function( event ) {
if(event.which == 13)
{
$.ajax({
type: "post",
url: '<?php echo 'http://localhost/mcportal/public/post/comment/196675710685996' ?>',
data: {},
success: function (response) {
alert( 'Comment posted' );
}
});
}
});
有两种解决方案可以解决此问题:
- 为您的 if 条件添加左大括号
{
OR - 删除
}
的结束大括号(最后一个)