该代码在JSFiddle中不起作用

时间:2016-03-14 21:51:23

标签: jquery html css json

我使用了此页http://www.pureexample.com/jquery/get-json.html中的代码并粘贴到Fiddle

不知何故,jsfiddle中的代码不起作用,我也更改了URL,但问题仍然存在于jsfiddle中。我希望代码在jsfiddle中工作。我错过了什么问题?

HTML:

<a name="#ajax-getjson-example"></a>
<div id="example-section38">
  <div>Car sale report</div>
  <div id="div381"></div>
  <button id="btn382" type="button">Click to load car sale report (json type)</button>
  &nbsp;<a href="http://www.pureexample.com/backend/data/car-sale.json" target="_blank">Original car sale report</a>
</div>

jQuery的:

$(document).ready(function() {
  $("#btn382").click(function() {
    /* set no cache */
    $.ajaxSetup({
      cache: false
    });

    $.getJSON("http://www.pureexample.com/backend/data/car-sale.json", function(data) {
      var html = [];

      /* loop through array */
      $.each(data, function(index, d) {
        html.push("Manufacturer : ", d.Manufacturer, ", ",
          "Sold : ", d.Sold, ", ",
          "Month : ", d.Month, "<br>");
      });

      $("#div381").html(html.join('')).css("background-color", "orange");
    }).error(function(jqXHR, textStatus, errorThrown) { /* assign handler */
      /* alert(jqXHR.responseText) */
      alert("error occurred!");
    });
  });
});

enter image description here

0 个答案:

没有答案