我正在为一个网站开发股票交易所的jQuery修复。
编辑:它根据返回值更新网页上的ID/CLASS或输入值。
index.php:
<!doctype html>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<meta charset="utf-8">
<title>load demo</title>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
url: '/datacall/demo.json',
dataType: 'json',
success: function( resp ) {
$( '#div' ).val( resp.currency[0].amount );
},
error: function( req, status, err ) {
console.log( 'Something went wrong', status, err );
}
});
var end = parseInt($('#value').val());
var newend = parseInt($('#div').val());
var result = $( end * newend );
$('#clickme').click(function() {
$('#new').val( result );
});
});
</script>
<div>
<input type="hidden" value="2500" id="value" />
<input type="hidden" value="" id="div">
<input type="text" id="new" value="" readonly/>
<input type="button" value="Change" id="clickme" />
</div>
当前返回的结果是:
[object Object]
我也尝试过使用 .text() 方法将其返回到 div 中。
demo.json:
{ "currency" : [
{
"name" : "South Africa",
"code" : "ZAR",
"amount" : 0.14
},
{
"name" : "America",
"code" : "USD",
"amount" : 0.64
},
{
"name" : "Europe",
"code" : "GBP",
"amount" : 1.29
}
] }
请问有人能告诉我哪里做错了吗?
先谢谢了!
console.log(resp)
,它会返回什么? - MisterBlademo.json
页面的源代码吗?你尝试过console.log(resp);
吗? - Chris Kempenresp.currency[0].amount
实际上返回的是一个对象。请尝试使用console.log(resp.currency[0].amount)
来找出返回的数据/对象。 - Slevin