按钮的onClick()事件并不指向任何地方.ajax的success()可能存在一些问题。我无法弄清楚我对此的新内容。
var currentAuthor="";
var currentQuote="";
$(document).ready(function(){
$("#getMessage").on("click",function(){
$.ajax({
header:{
"X-Mashape-Key":"xE5Raw3acMmsh4dpp6HEk5WSbJtTp1X9TL3jsnue3VRzr5vNNa",
Accept: "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
url:"https://andruxnet-random-famous-quotes.p.mashape.com/?cat=",
success: function(response){
var r=json.parse(response);
currentQuote=r.quote;
currentAuthor=r.author;
$("#author").html(r.author);
}
});
});
});
答案 0 :(得分:5)
你有两个问题:
spring.resources.cache-period
headers
而不是JSON.parse
json.parse

var currentAuthor = "";
var currentQuote = "";
$(document).ready(function () {
$("#getMessage").on("click", function () {
$.ajax({
headers: {
"X-Mashape-Key": "xE5Raw3acMmsh4dpp6HEk5WSbJtTp1X9TL3jsnue3VRzr5vNNa",
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded"
},
url: "https://andruxnet-random-famous-quotes.p.mashape.com/?cat=",
success: function (response) {
var r = JSON.parse(response);
currentQuote = r.quote;
currentAuthor = r.author;
$("#author").html(r.author);
}
});
});
});