Click here to Skip to main content
14,689,403 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) {
              url: '/FileUpload/Uploaddocumentmethod?data=' + JSON.stringify(data)  + '&uploadDate=' + uploaddate,
              data: {
                  files: $scope.SelectedFiles
          }).then(function (response) {
          }, function (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.
Updated 3-Sep-20 0:06am

1 solution

You need to properly encode the data you're sending as part of the URL. Use encodeURIComponent, or jQuery's param method:
// 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[^]
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