Ajax请求返回404未找到

时间:2017-05-30 14:03:03

标签: jquery ajax opencart

我一直试图找到解决方案,但我似乎找不到一个。当我尝试执行以下ajax调用时,我收到了404响应。代码在localhost上正常工作,但是当我在远程服务器上传更改时,我收到错误

$('#button-upload').on('click', function() {
    $('#form-upload').remove();

    $('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" value="" /></form>');

    $('#form-upload input[name=\'file\']').trigger('click');

    if (typeof timer != 'undefined') {
        clearInterval(timer);
    }

    timer = setInterval(function() {
        if ($('#form-upload input[name=\'file\']').val() != '') {
            clearInterval(timer);

            $.ajax({
                url: 'index.php?route=common/filemanager/upload&token=<?php echo $token; ?>&directory=<?php echo $directory; ?>',
                type: 'post',
                dataType: 'json',
                data: new FormData($('#form-upload')[0]),
                cache: false,
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#button-upload i').replaceWith('<i class="fa fa-circle-o-notch fa-spin"></i>');
                    $('#button-upload').prop('disabled', true);
                },
                complete: function() {
                    $('#button-upload i').replaceWith('<i class="fa fa-upload"></i>');
                    $('#button-upload').prop('disabled', false);
                },
                success: function(json) {
                    if (json['error']) {
                        alert(json['error']);
                    }

                    if (json['success']) {
                        alert(json['success']);

                        $('#button-refresh').trigger('click');
                    }
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                }
            });
        }
    }, 500);
});

控制台错误是

POST https://example.com/admin/index.php?  route=common/filemanager/upload&token=jyHPuiTt1DjdemKjNWUbeZqOtHHj4Dxw 404 (Not Found)

调试时的几次尝试使我的托管服务提供商出于安全原因阻止了我的IP地址。如何使ajax请求显示为威胁并且我的托管服务提供商采取的安全措施可能导致错误?我实际上可以从浏览器的网址访问URL,但不能从ajax调用

访问

1 个答案:

答案 0 :(得分:0)

尝试使用此

url: '/index.php?route=common/filemanager/upload&token=<?php echo $token; ?>&directory=<?php echo $directory; ?>',