gpt4 book ai didi

javascript - 这个错误有什么建议吗?未捕获的类型错误 : $. ajax 不是函数

转载 作者:行者123 更新时间:2023-11-29 23:24:57 25 4
gpt4 key购买 nike

<分区>

好的,所以我一直收到此 ajax 错误,但不确定原因。如果我删除部分代码,则按钮会加载。我以前用过同样的代码,从来没有遇到过任何问题。

任何帮助都会很棒。

到目前为止我做了什么:

  1. 在堆栈中查找“Uncaught TypeError: $.ajax is not a function”并查看我的链接以确保它们不是原因。
  2. 检查我是否在页面加载后加载代码 (window.onload)。
  3. 回到旧代码,看看我是否改变了什么,我没有。
  4. Google 搜索。

注意:我删除了这段代码中的 API key ,但我在本地确实有一个有效的 key (对其进行了测试以确保它有效并且确实有效)。

HTML:

    <!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>GIFtastic</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--Reset style-->
<link rel="stylesheet" type="text/css" media="screen" href="../GIFtastic/assets/css/reset.css" />
<!--Bootstrap-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
<!-- My own CSS stylesheet -->
<link rel="stylesheet" type="text/css" media="screen" href="../GIFtastic/assets/css/style.css">
<!--JavaScript-->
<script src="../GIFtastic/assets/javascript/app.js"></script>
</head>

<body>

<div id="dogBtns"></div>



<!-- jQuery CDN -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
crossorigin="anonymous"></script>
<!-- Bootstrap CDN -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
<!--popper-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
</body>

</html>

JS:

/*jshint esversion: 6 */
window.onload = function () {
//1. Before you can make any part of our site work, you need to create an array of strings, each one related to a topic that interests you. Save it to a variable called `topics`.
// * We chose animals for our theme, but you can make a list to your own liking.
var topics = ["Collie", "German Shepherd", "Bernese Mountain Dog", "Australian Shepherd", "Golden Retriever", "Siberian Husky", "Border Collie"];
var resultNum = 9;

// 2. Your app should take the topics in this array and create buttons in your HTML.
// * Try using a loop that appends a button for each string in the array.

function createTopicBtns() {
var topicBtns = $("#dogBtns");
for (i = 0; i < topics.length; i++) {
var newTopicBtns = $("<button>" + topics[i] + "</buttons>");
newTopicBtns.attr({
"type": "button",
"class": "btn btn-outline-secondary active m-2",
"data-name": topics[i],
"text": topics[i]
});
console.log(newTopicBtns);
topicBtns.append(newTopicBtns);
}
}

/*3. When the user clicks on a button, the page should grab 10 static, non-animated gif images from the GIPHY API and place them on the page.
*/

var queryURL = "https://api.giphy.com/v1/gifs/search?q=collie&api_key=<apiKey>";

$.ajax({
url: queryURL,
method: "GET"
}).then(function (response) {
console.log(response);
});



/*When the user clicks one of the still GIPHY images, the gif should animate. If the user clicks the gif again, it should stop playing.
*/

/*Under every gif, display its rating (PG, G, so on).*/

/*This data is provided by the GIPHY API.
Only once you get images displaying with button presses should you move on to the next step.
Add a form to your page takes the value from a user input box and adds it into your topics array. Then make a function call that takes each topic in the array remakes the buttons on the page.
*/

createTopicBtns();


//window on load end
};

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com