Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Ajax success data show undefind

New member
Joined
Feb 14, 2023
Messages
10
I return a array object data Ajax success result then i print li tag but its show undefind

My Ajax code is

Code:
$.ajax({
        'method': 'GET',
        'url': base_url +'party/selectCities?id='+state,
        success: function(data) {
            var newData = data.replace(/\"/g, "")
            if(newData == ""){
            }else{
                var datas = JSON.stringify(newData);
                var jsdata = JSON.parse(datas);
                alert(jsdata);
                var html = ``;
                for(var i = 0; i<jsdata.length; i++){   
                    html += '<li ng-click="selectcityclubs(' + jsdata[i].city+ ');>' + jsdata[i].city+ '</li>';
                    }

                    $("#ClubCity").html(html);
            }
        }
});

here i alert the jsdata i get result like

Code:
 [{city:North Goa},{city:South Goa}]
but the li list show undefind, How to solve this issue..
please help me to solve this issue
 
New member
Joined
Feb 14, 2023
Messages
6
It looks like you are missing a double quote after the ng-click. Check out this snippet below.

Also utilizing the template literals (backticks) instead of using + to concatenate strings helps make things more readable.

Code:
let jsdata = [{
  city: 'North Goa'
}, {
  city: 'South Goa'
}];

let html = '';
for (var i = 0; i < jsdata.length; i++) {
  html += `<li ng-click="selectcityclubs(${jsdata[i].city});">${jsdata[i].city}</li>`;
}

$("#ClubCity").html(html);
 
Top