Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 基于API调用返回的数据构建滑块_Jquery_Html_Json_Ajax_Api - Fatal编程技术网

Jquery 基于API调用返回的数据构建滑块

Jquery 基于API调用返回的数据构建滑块,jquery,html,json,ajax,api,Jquery,Html,Json,Ajax,Api,需要构建一个滑块(旋转木马),它应该基于API调用返回的数据。有3个值,我需要拉图像,标题和说明 它必须是图片、标题和说明(在每张幻灯片上,从JSON中提取) jQuery var myJSON = 'apiCall'; $.getJSON('myJSON, { get_param: 'value' }, function(data) { $.each(data, function(index, element) { $('body').append($('<img

需要构建一个滑块(旋转木马),它应该基于API调用返回的数据。有3个值,我需要拉<代码>图像,
标题
说明

它必须是
图片
标题
说明
(在每张幻灯片上,从JSON中提取)

jQuery

var myJSON = 'apiCall';
$.getJSON('myJSON, { get_param: 'value' }, function(data) {
    $.each(data, function(index, element) {
        $('body').append($('<img>', {  
        }));
    });
});
var myJSON='apiCall';
$.getJSON('myJSON,{get_param:'value'},函数(数据){
$.each(数据、函数(索引、元素){
$('body')。追加($('body')

让html=`
${title}
${Graph}

` $(“.carousel-inner”)[0]。追加(html)
把上面的代码放在一个循环中,你应该已经准备好了。 imgSrc、title和paragraph应通过API调用动态生成。

let html=`
${title}
${Graph}

` $(“.carousel-inner”)[0]。追加(html)
把上面的代码放在一个循环中,你应该已经准备好了。 imgSrc、title和paragraph应该从API调用中动态生成。

$.get('apiCall')
.然后(功能(响应){
变量$carousel=$(“#carouselExampleIndicators”);
var$carouselInner=$carousel.find('.carousel-inner');
response.data.forEach(功能(第i项){
var模板=“”;
如果(i==0){
模板=“”;
}否则{
模板=“”;
}
模板+='';
模板+='';
模板+=''+项目标题a+'';
模板+=''+item.category+'

'; 模板+=''; 模板+=''; $carouseliner.append(模板); }) $carousel.carousel(); })

$.get('apiCall')
.然后(功能(响应){
变量$carousel=$(“#carouselExampleIndicators”);
var$carouselInner=$carousel.find('.carousel-inner');
response.data.forEach(功能(第i项){
var模板=“”;
如果(i==0){
模板=“”;
}否则{
模板=“”;
}
模板+='';
模板+='';
模板+=''+项目标题a+'';
模板+=''+item.category+'

'; 模板+=''; 模板+=''; $carouseliner.append(模板); }) $carousel.carousel(); })


描述当你说在将数据推送到幻灯片时遇到问题的意思描述当你说在将数据推送到幻灯片时遇到问题的意思谢谢,我看到它在工作,但当我添加到我的代码时,它没有。我链接了json,可能是关于json结构的?是的,你需要调整模板r json属性。我编辑了上面的代码(我添加了您提供的json),所以您现在可以尝试。我看到它现在可以工作了。谢谢!您能告诉我,为什么您认为我的控制台中存在此错误?“未捕获引用错误:$未定义”和“$.get不是函数”我有所有库(jQuery和Bootstrap)未正确包含linked.jQuery库。请检查包含脚本的顺序。您的javascript必须包含在jQuery和引导脚本下面。抱歉,我没有时间帮助您实现这一点。我想我在提供的示例中已经帮了您很多忙。谢谢,我看到它正在工作,但当我添加到代码中时,我发现没有。我链接了json,可能是关于json结构的?是的,你需要调整json属性的模板。我编辑了上面的代码(我添加了你提供的json),所以你现在可以尝试。我看到它现在可以工作了。谢谢!你能告诉我,为什么你认为我的控制台中有这个错误?“未捕获引用错误:$未定义”还有“$.get不是函数”我有所有库(jQuery和Bootstrap)未正确包含linked.jQuery库。请检查包含脚本的顺序。您的javascript必须包含在jQuery和引导脚本的下面。抱歉,我没有时间帮助您实现这一点。我想我在提供的示例中已经帮了您很多。
   <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
             <ol class="carousel-indicators">
               <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
  </ol>
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-80" src="..." alt="First slide">
        <div class="carousel-caption d-none d-md-block">
         <h5></h5>
         <p></p>
        </div>
    </div>
    <div class="carousel-item">
      <img class="d-block w-80" src="..." alt="Second slide">
        <div class="carousel-caption d-none d-md-block">
         <h5></h5>
         <p></p>
        </div>
  </div>
    </div>
    <div class="carousel-item">
      <img class="d-block w-80" src="..." alt="Third slide">
       <div class="carousel-caption d-none d-md-block">
         <h5></h5>
         <p></p>
       </div>
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>
let html = `
<div class="carousel-item">
      <img class="d-block w-80" src="${imgSrc}" alt="Second slide">
        <div class="carousel-caption d-none d-md-block">
         <h5>${title}</h5>
         <p>${parangraph}</p>
        </div>
  </div>
`
$(".carousel-inner")[0].append(html)