I have an address field in the locations database, with a value " Shop 2197 - Block 1014 - Road 90 - Al-Delaa' Complex - Hamala ", the website was working great until I added the location with this address, the google maps plugin no longer works because this single quote has caused a javascript error in the console,
My location controller get function:
public static function get() {
$locations = Location::with('country')->get();
return $locations;
}
My script for loading locations into google maps:
var locations = JSON.parse('{!! $locations !!}');
var lang = "";
$(locations).each(function(key, value) {
allLocationsPins.push({lat: parseInt(value.latitude), lng: parseInt(value.longitude)});
});
The single quote in the address value is causing this error because it's not escaped. I tried adding the JSON encode function to the locations array before returning it from the controller but nothing happened, I think escaping the single quote by Json_encode is not working becaouse of the {!! $locations !!} in the script file, but if i tried to remove the {!! !!} every character in the string change.
How can i fix this? if json_encode is not working what else can i use ?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2zDgec2
via IFTTT
Aucun commentaire:
Enregistrer un commentaire