mardi 19 juillet 2016

print checked with .each and ajax

I have ajax request, and a html with textboxes, get from ajax "1" and a date, i need print many checkboxes.

 $.ajax({
     type:'POST',
     url:pathJS+'/php/requisitos/documents.php',
     async:false,
     dataType:'json'
  }).done(function(docs){
          //docs return - actJSON "1" factJSON "22/Jun/2016" curpJSON "1" fcurpJSON "08/Jul/2016"

         //actJSON and CURPJSON are my data from ajax request(docs)
         mapping = {"actJSON":['actCheck','actF], "curpJSON":['curpCheck',curpf'], etc...}


    //In this part i don't have any idea and actcheck, actf, curpCheck and curpf my checks and vids
    $.each(docs, function (idx, val) { 
        $.each (mapping[val], function (i, v) { //iterate over the selections
            $('#' + v).prop('checked', true); //set the checkbox
        });        
    });   




Aucun commentaire:

Enregistrer un commentaire