Hi some part of our site just keeps loading and when I try to check via Inspect element I have a error of Uncaught SyntaxError: Unexpected token ; and as per checking i have problem with this code
<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);
}
});
}
I also try to remove ; from 2nd line but no luck. Anyone can help? Thanks!
Your problem is in the first row:
<?php echo "var place =".$city.";"; ?>
Strings should be around quotes or apostrophes, so change it to
<?php echo "var place = '$city';"; ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.