Ajax call with jquery-fileupload

2019-04-16 02:57发布

问题:

I have following error when load jquery-fileupload on my website:

http://www.testsite.net/uploadfile/%5Bobject%20Object%5D?_=1354103435936

error is (page response)

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html><head>
    <title>404 Not Found</title>
    </head><body>

<h1>Not Found</h1>    
<p>The requested URL was not found on this server.</p>

</body></html>

reading main.js I found error in this call:

    // Load existing files:
    $.ajax({
        // Uncomment the following to send cross-domain cookies:
        //xhrFields: {withCredentials: true},
        url: $('#fileupload').fileupload('option', 'url'),
        dataType: 'json',
        context: $('#fileupload')[0]
    }).done(function (result) {
        if (result && result.length) {
            $(this).fileupload('option', 'done')
                .call(this, null, {result: result});
        }
    });

回答1:

i fixed the error by including the main.js on $(document).ready()

so that functions in main.js can detect the

$(document).ready(function(){

  $.getScript('js/main.js');

  // make sure that the url in the main.js is correct
  // and if you still got errors, set timer
  // 
  // setTimeout(function(){
  //
  // 	$.getScript('js/main.js');
  // }, 1000);
  // 
  // after 1 second, the main.js will be included in the file

});