Ad

Page Content Won't Load And Uncaught SyntaxError: Unexpected Token ;

- 1 answer

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!

Ad

Answer

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';"; ?>
Ad
source: stackoverflow.com
Ad