0

i have a menu. These menu includes some artists and when admin clicks checkboxes, the artists is inserted to DB.

first of all,

function AddDataImdb(par, par2, par3) {

    var artistIds = [];
    $("input[name='" + par + "']:checked").each(function () {
        artistIds.push($(this).val());
    });

    $.post('/json/management/AddDataImdbAjax', {
        "artistIds": artistIds
    }, function (response) {
        if (response == 'error') {

            alert("Sanatçı bulunamadı, yönlendiriliyorsunuz");
            window.location.replace("myurl");

        } else {
            alert("succesfully added");
            $("#" + par2 + "").append(('<br /><input type="checkbox" name =' + par + ' value=' + response + ' />' + par3 + '<br />'));
        }
    });

}

With above code, i can add my div the new added artists.

The problem is that when admin insert 2 or more artist, it shows the last one as added

$("#"+par2+"").append(('<br /><input type="checkbox" name ='+par+' value='+response+' />'+par3+'<br />'));

Above code add the div. How can i add these as array ? What can i do ?

2
  • what is your response? it is not showing the last div, I think it appends only one div. To add multiple div you should loop over your response Commented Apr 26, 2012 at 17:42
  • It's not clear to me what you're wanting to occur. Do you want a new checkbox created if there are multiple values that come back in the response? How is response formatted? Commented Apr 26, 2012 at 17:43

1 Answer 1

1

can you state more? what is the content of the response?

if your response is a list then you may do this:

$.each(reponse, function () {
    //append as div
}):
Sign up to request clarification or add additional context in comments.

2 Comments

var myArr = response; i took my json like that can i use this like foreach in php ?
try using $.each(reponse, function (index, value) { }); OR $.map(response, function (value, key) { });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.