Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I made a complete javascript function using jquery and ajax to upload files ... Everything is working perfectly untill I realized that for some files the error function is fired in ajax instead of success function. Below is my code:

$.ajax({
           url: 'MyService.asmx/UploadFiles',
           type: "POST",
           contentType: false,
           processData: false,
           data: fileData,   // form data that contains file and some data
           dataType: "text",
           success: function (response) {
             ...
           }
           error: function (jqXHR, exception) {
              //alert(jqXHR.status);
              var msg = '';
              if (jqXHR.status === 0) {
                  msg = 'Not connect.\n Verify Network.';
              } else if (jqXHR.status == 404) {
                  msg = 'Requested page not found. [404]';
              } else if (jqXHR.status == 500) {
                  msg = 'Internal Server Error [500].';
              } else if (exception === 'parsererror') {
                  msg = 'Requested JSON parse failed.';
              } else if (exception === 'timeout') {
                  msg = 'Time out error.';
              } else if (exception === 'abort') {
                  msg = 'Ajax request aborted.';
              } else {
                  msg = 'Uncaught Error.\n' + jqXHR.responseText;
              }
              alert(msg);
           }
    });


The error thrown is "Not connect.\n Verify Network". I have searched for this error I found that it is thrown when service is not reachable or when cross-site scripting (access is denied) ... The weird thing is that some files are uploaded successfully, others are not, which means service is reachable and access is not denied ... And concerning file types, they are all docs files with max size of 5 MB, whenever I delete everything inside the file that could not be uploaded and I try again to upload: function succeeds...
I am firing the upload function in onchange event:
<input type="file" class="HideFile" onchange="UploadFilesnew();" onclick="resetInput(this)" id="UploadFilenew" /> ; 

My input is inside an asp:UpdatePanel in a .aspx page, so no forms and actions ...
So why some files are uploaded successfully and others are not? How can I resolve my problem in order to be able to upload all files?

What I have tried:

I have tried to return false on change as it was suggested in some solutions:
<input type="file" class="HideFile" onchange="UploadFilesnew();return false;" onclick="resetInput(this)" id="UploadFilenew" /> ; 


But it did not work

I have also installed the latest jquery version as I had an old one, but did not work
Posted
Updated 19-Mar-17 23:05pm

1 solution

I found it:
I have just added this block in my web.config file
<system.web>
     <httpRuntime maxRequestLength="1048576" />
</system.web>


The problem was when file size is nearest 5MB, then the request fails
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900