SyntaxError:JSON输入意外结束,jQuery $ .ajax调用

时间:2018-07-05 10:54:50

标签: javascript jquery ajax api

我不断收到以下错误,似乎无法找出我在做什么,任何帮助将不胜感激。

SyntaxError: Unexpected end of JSON input
at parse (<anonymous>)
at Ut (jquery-3.3.1.min.js:2)
at k (jquery-3.3.1.min.js:2)
at XMLHttpRequest.<anonymous>

var jsonData = {
  "artist": artistName,
  "album": albumName,
  "track": trackTitle,
  "baseUrl": spotifyLink,
  "mediaType": "Music",
  "title": trackTitle,
  "code": artistName,
  "domainId": domainID
};
jsonData = JSON.stringify(jsonData);

$.ajax(
  'https://api.linkfire.com/campaigns/boards/' + boardID + '/links', {
    type: 'POST',
    dataType: 'json',
    beforeSend: function(xhr) {
      xhr.setRequestHeader("content-type", "application/json");
      xhr.setRequestHeader("Authorization", "Bearer " + window.access_token);
    },
    data: jsonData,
    complete: function(response) {
      console.log(response);
    },
    error: function(jqXHR, textStatus, errorThrown) {
      console.log(errorThrown, textStatus, jqXHR);
    }
  }
);

0 个答案:

没有答案