encodeURIComponent не работает с Rest Api. Невозможно получить результат - PullRequest
0 голосов
/ 06 сентября 2018

Я пытаюсь передать данные между сервером и приложением с помощью Rest API. Ссылка Rest API должна быть декодирована, и здесь происходит участие encodeURIComponent для декодирования ссылки Rest API. Результат, который я получаю, действительно странный, изображения загружаются после загрузки .

Ссылка для моего временного Сервера. http://freaksearch.com/aarti/rest-api.php?json=image&Id=

Вот как я использую encodeURIComponent:
encodeURI ('http://freaksearch.com/aarti/rest-api.php?json=' + encodeURIComponent (' image & Id ') + imageId),

$scope.download = function(imageId, imageHeading) {
    $ionicLoading.show({
      template: 'Downloading...'
    });
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
          fs.root.getDirectory(
              "MyProject",
              {
                create: true
              },
              function (dirEntry) {
                dirEntry.getFile(
                    imageHeading + ".jpg",
                    {
                      create: true,
                      exclusive: false
                    },
                    function gotFileEntry(fe) {
                      var p = fe.toURL();
                      fe.remove();
                      ft = new FileTransfer();
                      ft.download(
                          encodeURI ('http://freaksearch.com/aarti/rest-api.php?json=' + encodeURIComponent('image&Id=') + imageId),
                          p,
                          function (entry) {
                            $ionicLoading.hide();
                            $scope.imgFile = entry.toURL();
                          },
                          function (error) {
                            $ionicLoading.hide();
                            alert("Download Error Source --> " + error.source);
                          },
                          false,
                          null
                      );
                    },

                    function () {
                      $ionicLoading.hide();
                      console.log("Get the file failed");
                    }
                );
              }
          );
        },
        function () {
          $ionicLoading.hide();
          console.log("Request for filesystem failed");
        });
  }
  $scope.load = function(imageId, imageHeading) {
    $ionicLoading.show({
      template: 'Loading...'
    });
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
        fs.root.getDirectory(
            "ExampleProject",
            {
                create: false
            },
            function(dirEntry) {
                dirEntry.getFile(
                    imageHeading + ".jpg",
                    {
                        create: false,
                        exclusive: false
                    },
                    function gotFileEntry(fe) {
                        $ionicLoading.hide();
                        $scope.imgFile = fe.toURL();
                    },
                    function(error) {
                        $ionicLoading.hide();
                        console.log("Error getting file");
                    }
                );
            }
        );
    },
    function() {
        $ionicLoading.hide();
        console.log("Error requesting filesystem");
    });
}
...