How to send API request using java script?I'm following the below code , but i'm not able to display it can you suggest me the code?

两盒软妹~` 提交于 2019-12-25 18:35:27

问题


<script type="text/javascript"> 
    $(document).ready(function() { 
    $.getJSON(stg.api.bazaarvoice.com/data/reviews.json?apiversion=5.4&passkey=ywwm6ry3sw5r4ak9j7f2x9ed&filter=productid:<?php echo $product?>&stats=reviews 
    function(json){var output = json);
    $("#BVRReview").append(output);
    }); 
});
</script>

回答1:


Here is a JSFiddle that demonstrates how you can retrieve data from your API using a jQuery AJAX request.

It will output the AuthorId and ReviewText into a div for demonstration purposes.

$(document).ready(function(){
    $.ajax({
        url: "https://stg.api.bazaarvoice.com/data/reviews.json?apiversion=5.4&passkey=ywwm6ry3sw5r4ak9j7f2x9ed",
    data: "json",
    success: function(data){
        console.log(data);
      for (i in data['Results']){
        var info = data['Results'][i];
        $('.results').append(info.AuthorId + "</br>" + info.ReviewText + "</br></br>");
      }
    }
  })
});


来源:https://stackoverflow.com/questions/35794439/how-to-send-api-request-using-java-scriptim-following-the-below-code-but-im

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!