Распарсить JSON
Здравствуйте. Помогите пожалуйста разобраться. Делаю запрос со стороннего сервера. Клиентская часть:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>jQuery. getJSON</title>
<meta name="description" content="jQuery library, AJAX. getJSON Function" />
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.js'></script>
<link href="style.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<script>
$(document).ready(function () {
$("#button").click(function () {
$.ajax({
url:'http://www.demo.ru/?id=ws&action=search&login=admin&pass=admin&detail num=MB831042&cross=1&format=json&callback=?',
dataType:'jsonp',
success:function(json) {
var res = jQuery.parseJSON(json);
var count = 0;
for (o in res) {
if ((res[count].quantity > 1) & (res[count].timegar < 30)) {
jQuery('#example-4').append('<table>')
jQuery('#example-4').append('<tr><th>' + res[count].detailnum + '</th><th>' + res[count].detailname + '</th><th>' + res[count].makename + '</th><th>'+ Math.round(res[count].pricerur*1.2)+ '</th><th>' + res[count].timegar + '</th></tr>');
jQuery('#example-4').append('</table>')
}
count++;
}
}
});
});
});
</script>
<div class="example cursor" id="example-4">Click to load JSON data</div>
<div id="button" style="width:300px; height:300px; border:solid 1px red;"></div>
</body>
</html>
В консоли мозилы приходит ответ:
[{"makename":"Mitsubishi","makelogo":"MC","detailnu m":"MB831042","detailname":"РЫЧАГ МАЯТНИКОВЫЙ","pricerur":"1374.43","quan tity":"29","time":"1","timegar":"3","country":"М сква","supcode":"2191","statistic":"91"}]
А на страницу ответ не выводится (( в чем загвоздка? Если можно ответьте с пояснениями пожалуйста.
|