S
S
slanec2018-04-04 18:15:44
Joomla
slanec, 2018-04-04 18:15:44

How to upload images to joomla using ajax?

I need to load the image using Ajax, but the problem is that even if I do not display anything in the module function, a copy of the page is returned.
js code:

function uploadServer($el) {
var fileUpload = $el.get(0);
var file = fileUpload.files[0];
var url;
if (file) {
    var data = new FormData();
    data.append('image', file);

    var request = {
        'option': 'com_ajax',
        'module': 'constructor',
        'method': 'uplodeImage',
        'val'   :  data,
        'format': 'raw',
    };
    console.log(request);
    $.ajax({
        async: false,
        type: 'post',
        cache: false,
        contentType:false,
        processData:false,
        data: request,
        success: function (response) {
            url = response;
        }
    }).done(function(response){
        url = response;
    });
}
$('#debug').html(url);
return url;
}

joomla module:
class modConstructorHelper
{

    // Загрузка изображений во временную папку 
    public static function uplodeImage() {

        jimport('joomla.application.module.helper');
        jimport('joomla.application.input.files');

    }

}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question