Tzahi Tzahi - 1 year ago 83
HTML Question

try to get data fro json

I will try to get data from url json but nothing append
this is my code vere simple:

<title>The jQuery Example</title>
<script type = "text/javascript"
src = ""></script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
$.getJSON('', function(jd) {
$('#stage').html('<p> Name: ' + + '</p>');
$('#stage').append('<p>Age : ' + jd.item.itemId+ '</p>');
$('#stage').append('<p> Sex: ' + jd.item.salePrice+ '</p>');
<p>Click on the button to load result.html file:</p>
<div id = "stage" style = "background-color:#cc0;">
<input type = "button" id = "driver" value = "Load Data" />

some can know why I don't see nothing?

Answer Source

The problem is with a cross domain Request. You could make an ajax with dataType: "jsonp" to solve your issue.

Look here for better explanation.


as already pointed out, you should access to your response data without the .item, so become

$(document).ready(function() {
  $("#driver").click(function(event) {
      url: '',
      data: {
        format: 'json',
        apiKey: 'fc5cku3vruymkhxhvtenm9bk'
      dataType: 'jsonp',
      success: function(jd) {
        $('#stage').html('<p> Name: ' + + '</p>');
        $('#stage').append('<p>Age : ' + jd.itemId + '</p>');
        $('#stage').append('<p> Sex: ' + jd.salePrice + '</p>');
<script src=""></script>
<p>Click on the button to load result.html file:</p>
<div id="stage" style="background-color:#cc0;">
<input type="button" id="driver" value="Load Data" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download