-1

i have passed two strings and one list to a controller using an ajax call.From controller i can retrieve my string values. but the list that i passed come as an object. how to convert that object to a list.

this is my ajax

var imagelist = [];
if ('files' in x) {
    if (x.files.length == 0) {
        alert("Add one or more images");
        ss
    } else {
        for (var i = 0; i < x.files.length; i++) {

            imagelist.push(x.files[i]);

        }
    }
    jQuery.ajaxSettings.traditional = true;
    $.ajax({
        url: url_path,
        type: 'POST',
        data: {
            'pname': pname,
            'des': des,
            'ilist': imagelist
        },
        success: function(data) {
            alert("test");
        },
        error: function(request, error) {
            alert("error");
        }
    });
}

controller is

 $images = $this->input->post('ilist');

    foreach($images as $img){


    }

this is the value that $images get

 [object File]

1 Answers1

-1

Try sending the images with formdata object

  • 2
    Hi. If a question has a duplicate, then the question should rather be closed as a duplicate instead of being answered again. Also, an answer should contain a proper code example, not just "try using this or that". Show _how_ they could use "this" or "that" to solve the issue. – M. Eriksson Aug 10 '19 at 17:44