XMLHttpRequest服务器中的FormData响应未显示对象

时间:2016-10-14 21:47:22

标签: javascript ajax node.js xmlhttprequest

以下是我在服务器中收到的回复

{ '------WebKitFormBoundaryBysveoDpXjlRjoJV\r\nContent-Disposition: form-data; name': '"Title"\r\n\r\nForrest Gump\r\n------WebKitFormBoundaryBysveoDpXjlRjoJV\r\nContent-Disposition: form-data; name="Released"\r\n\r\n06 Jul 1994\r\n------WebKitFormBoundaryBysveoDpXjlRjoJV\r\nContent-Disposition: form-data; name="Poster"\r\n\r\nhttps://images-na.ssl-images-amazon.com/images/M/MV5BYThjM2MwZGMtMzg3Ny00NGRkLWE4M2EtYTBiNWMzOTY0YTI4XkEyXkFqcGdeQXVyNDYyMDk5MTU@._V1_SX300.jpg\r\n------WebKitFormBoundaryBysveoDpXjlRjoJV\r\nContent-Disposition: form-data; name="Genre"\r\n\r\nComedy, Drama\r\n------WebKitFormBoundaryBysveoDpXjlRjoJV\r\nContent-Disposition: form-data; name="Director"\r\n\r\nRobert Zemeckis\r\n------WebKitFormBoundaryBysveoDpXjlRjoJV\r\nContent-Disposition: form-data; name="Rated"\r\n\r\nPG-13\r\n------WebKitFormBoundaryBysveoDpXjlRjoJV--\r\n' }

我不知道如何发送FormData来访问它。

这是代码:

var setCurrentlyDisplayedMovie = function(movie){
    var formData = new FormData();

    formData.append('Title', movie.Title);
    formData.append('Released', movie.Released);
    formData.append('Poster', movie.Poster);
    formData.append('Genre', movie.Genre);
    formData.append('Director', movie.Director);
    formData.append('Rated', movie.Rated);

    currentlyDisplayedMovie = formData;

    // console.log(currentlyDisplayedMovie);
  };

var favoriteCallback = function(){
    var data = getCurrentlyDisplayedMovie();

    xhttp.open('POST', '/favorites');


    xhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        console.log(success);
      }
      else {
        console.log(xhttp.status);
      }
    };


    xhttp.setRequestHeader('Content-Type', 'multipart/form-data');
    xhttp.setRequestHeader('Process-Data', 'multipart/form-data');
    xhttp.send(data);
};

0 个答案:

没有答案