简体   繁体   中英

404 not found when sending post request to controller

I am calling a controller name batch_processor with the method parseFile defined.

I have a script as:

<script>
$(document).ready(function() {
    $('#xmlfile').multi();
});

let parseFile = (update) => {
    var xml = $('#xmlfile').val() || [],
    payload = {xmlfiles: xml};
    if(update) {
        payload['update'] = 'y';
    }
    $.post('/batch_processor/parseFile/1', payload, 
        function(data, textStatus, xhr) {
            var res = JSON.parse(data);
            $('#xml').val(res.xml);
            $('#parsed').val(JSON.stringify(res.parsed, null, '\t'));
            $('#manifest').val(JSON.stringify(res.manifest, null, '\t'));
            $('#report').val(JSON.stringify(res.report, null, '\t'));
        }
    );
};

So, when ParseFile Button is clicked this script is invoked. I have defined parseFile method inside batch_processor controller. Still I am getting 控制台消息

404表示您尝试访问服务器上的资源不存在

Why is there the "/1" in your url ? I think you can try to remove them. try again

check whether you have defined the parameter in function (parseFile($file_id)) . For that check the same without parameter**(/batch_processor/parseFile)** . If it is working then it can be the issue with parameter. If that doesn't work check whether you have defined htaccess to avoid index.php from url. if not add it.

Error 404 is thrown when URL you are trying to send your data to doesn't exist.

Check if /batch_processor/parseFile/1 doesn't have any typo in it (I can see mixed naming conventions - maybe that is it?) and if it has valid route to proper controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM