我试图找到下面的代码的输出:未捕获的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标签不匹配 - 这似乎并没有影响我目前的问题。 –
我解决了您的问题...查看解答的答案。 –