Click here to Skip to main content
15,886,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i upload file using jquery ajax calling. here is my code:

$scope.UploadFiles = function (files, data) {
      $scope.SelectedFiles = files;

     var uploaddate= $("#uploaddate").val();


      if ($scope.SelectedFiles && $scope.SelectedFiles.length) {
          Upload.upload({
              url: '/FileUpload/Uploaddocumentmethod?data=' + JSON.stringify(data)  + '&uploadDate=' + uploaddate,
              data: {
                  files: $scope.SelectedFiles
              }
          }).then(function (response) {
              alert("Success")
          }, function (error) {
             alert("ERROR")
          });
      }
  };


and controller method code is :

public void Uploaddocuments(string Data, string uploaddate)
{
   my code...
}


i pass date with timezone (
23.09.2020 14:00 +0530 
) in jquery. but in controller i got date format like (
23.09.2020 14:00 0530 
) . it remove "+" sign from date.Can any one suggest me where i am wrong.

What I have tried:

i search on google but not getting any solution related to this issue.
Posted
Updated 2-Sep-20 23:06pm

1 solution

You need to properly encode the data you're sending as part of the URL. Use encodeURIComponent, or jQuery's param method:
JavaScript
// Either:
url: '/FileUpload/Uploaddocumentmethod?data=' + encodeURIComponent(JSON.stringify(data)) + '&uploadDate=' + encodeURIComponent(uploaddate)

// Or:
url: '/FileUpload/Uploaddocumentmethod?' + $.param({data: JSON.stringify(data), uploadDate: uploaddate})
encodeURIComponent() - JavaScript | MDN[^]
jQuery.param() | jQuery API Documentation[^]

But you're going to need to use a FormData object if you want to upload files via AJAX:
Using FormData Objects - Web APIs | MDN[^]
 
Share this answer
 
v2
Comments
TCS54321 3-Sep-20 5:55am    
Thank you so much. it's working fine for me. You save my day.

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