我試圖找到下面的代碼的輸出:未捕獲的ReferenceError:請求沒有定義,試圖解析JSON
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
function request(){
var URL = " http://jsonplaceholder.typicode.com/posts/1」;
$.ajax({
type: "GET",
url: URL,
contentType: "application/json; charset=utf-8",
data: 「{}」,
dataType: "jsonp",
success: function(msg) {
var json = msg; //NOTE since we said we’re getting back jsonp, jQuery did the parsing for us!
document.getElementById("current").innerHTML=json.title;
},
error: function (xhr, ajaxOptions, thrownError) {
document.getElementById("current").innerHTML = 「Error fetching 「 + URL;
}
});
}
</script>
<button type="button" onclick="request()"></button>
<div id="output"></div>
</body>
<html>
我寫的最後部分,按鈕和刻度。我很好奇經過解析的JSON的輸出是什麼,但是當我嘗試運行它時發生錯誤 - 函數「request」沒有被定義。我認爲這與src有關,但我相信我需要那裏,因爲我本身沒有Jquery。我試着環顧四周,其他所有人都看到這個問題完全不同。我是如何寫這個的嗎?
在此先感謝。
'數據:「{}」,'是完全錯誤的......語法錯誤! –
爲了記錄,我意識到ID標籤不匹配 - 這似乎並沒有影響我目前的問題。 –
我解決了您的問題...查看解答的答案。 –