1

I need to upload an image to the server via AJAX, but the server comes back to the page with request, although server doesn't send anything.

ajax:

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;

module:

class modConstructorHelper
{
    // Загрузка изображений во временную папку 
    public static function uplodeImageAjax() {
        jimport('joomla.application.module.helper');
        jimport('joomla.application.input.files');
    }
}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.