gpt4 book ai didi

javascript - 页面内容无法加载并且未捕获语法错误 : Unexpected token ;

转载 作者:行者123 更新时间:2023-11-27 23:27:55 25 4
gpt4 key购买 nike

您好,我们网站的某些部分一直在加载,当我尝试通过 Inspect 元素检查时,出现错误 Uncaught SyntaxError: Unexpected token ;根据检查,我对这段代码有问题

<script>
<?php echo "var place =".$city.";"; ?>
jQuery(document).ready(function(){
//console.log(place);
getLocation();
//get_locations(place.city,'<?php echo BASE_URL.'clinics/get_near_locations'; ?>');
});

function getLocationByCity(data){
var city = place.city;
var url = '<?php echo BASE_URL.'clinics/get_near_locations'; ?>';

// if(city!='false')
// jQuery('#current-city').html('Current City: '+city);


jQuery.ajax({
url:url,
type: 'POST',
dataType: 'html',
data:'city='+city,
beforeSend: function(){
jQuery('.button').html('<span>Please wait...</span>');
},
success: function(data){

jQuery('#clinic-locations').html(data);
}
});

}


function getLocation()
{

if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(getLocationByLatLong,errorHandler,{timeout:6000});
}else{
getLocationByCity();
}
}

function errorHandler(err)
{
console.log(err);
console.log('errorHandler');
getLocationByCity();
}



function getLocationByLatLong(position)
{

jQuery.ajax({
url:'<?php echo BASE_URL.'clinics/get_near_locations'; ?>',
type: 'POST',
dataType: 'html',
data:'latitude='+position.coords.latitude+'&longitude='+ position.coords.longitude,
beforeSend: function(){
jQuery('.button').html('<span>Please wait...</span>');
},
success: function(data){
jQuery('#clinic-locations').html(data);
}
});
}

我也尝试从第二行删除 ; 但没有运气。有人可以帮忙吗?谢谢!

最佳答案

您的问题在第一行:

<?php echo "var place =".$city.";"; ?>

字符串应该用引号或撇号括起来,因此将其更改为

<?php echo "var place = '$city';"; ?>

关于javascript - 页面内容无法加载并且未捕获语法错误 : Unexpected token ;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34803237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com