I try to pass a data code igniter controller to ajax request the written function not working
Controller
public function selectPlaygrounds() {
$data = $this->branchatm->getCitiesFromState($state);
$result='';
if($data){
foreach($data as $list){
$result.="<li ng-click='sawAll($list->city);'>$list->city</li>";
}
}
sendJsonResponse($result);
}
Ajax call
$.ajax({
'method': 'GET',
'url': base_url +'Ground/selectPlaygrounds',
success: function(data) {
var newData = data.replace(/"/g, "")
if(newData == ""){
}else{
$("#ls-city-grnd").html(newData);
}
}
});
Here result show in browser network tab
<li ng-click='sawAll(North Goa);'>North Goa</li>
<li ng-click='sawAll(South Goa);'>South Goa</li>
I wand result use quotes around the name of the city inside the sawAll function like this
<li ng-click="sawAll('North Goa');">North Goa</li>
Any idea to solve this issue?
2
Answers
Just replace your
li
in controller like thisUpdated Solution
you can use the htmlspecialchars() function as following.
Hope this will help you.
To add quotes around the city name, you need to check which quote in your string needs to be escaped and which not. If this is your target string:
…adding it could work like this: