jqueryajaxuploadcare

Uploadcare recognise file with dynamic loaded url


I am using Uploadcare on my site and I am loving it.

I have one problem though I am using a bootstrap modal which I load the data through AJAX. I want Uploadcare widget to recognise that the file already exists and show the picture (not ask to upload new). Is there a way to force the widget to refresh and read the value="". If I set the value before it works as intended.

My code is below: data[4] returns the URL of the Uploadcare image

<input type="hidden"
       id="editurl"
       name="url"
       role="uploadcare-uploader"
       data-crop=""
       data-images-only="true">

$.ajax({
        type: "POST",
        dataType: "json",
        url: "worker.php",
        data: "action=details&id="+ id +"",
        error: function() {
            show_notification("danger", "warning-sign", "Ajax query failed!");
        },
        success: function(data) {
            $("#editurl").val(data[4]);
        }
    });

Solution

  • You just need the following in success handler:

    var widget = uploadcare.Widget('#editurl');
    widget.value(data[4]);
    

    More info may be found on JS API documentation page.