Home > Enterprise >  How to pass the data as object in jquery ajax
How to pass the data as object in jquery ajax

Time:07-04

I want to receive the value thought iterator, when I use

$('#someModal').find('input[name=nameProBangHHModal]').val(data[0].TenNhanQuyCach); 

it works as expected.

But when I use an iterator, the return shows [object Object].TenNhanQuyCach - not the data returned.

I try to search for other topic but I'm stuck on this. How to get the data returned in array[data[0]] with the value from the iterator method?

Thank you for your time!

$.ajax({
            url: 'someurl to retrive data',
            type: 'POST',
            data: {id:id},
            success: function(data,status) {
                var tenCot = ['nameProBangHHModal','valueBangHHModal',];
                var tenCotTrongCsdl = ['TenNhanQuyCach','DonViTinh',];
                console.log(tenCotTrongCsdl[0]);
                for (i=0;i <= tenCot.length - 1;i  ) {
                    $('#someModal').find('input[name="'   tenCot[i]   '"]').val(data[0] '.' tenCotTrongCsdl[i]');
                }

CodePudding user response:

oh i find out the answer after search topic for array: this one: How can I access and process nested objects, arrays or JSON?. and find out that need to use [] for variable, not the ".". this one work for me:

$('#someModal').find('input[name="'   tenCot[i]   '"]').val(data[0][tenCotTrongCsdl[i]]);
  • Related