Sto lavorando ad una correzione jQuery di Borsa per un sito web.jQuery restituisce la chiamata AJAX [oggetto oggetto]
MODIFICA: aggiorna un ID/CLASS o un valore di input sulla pagina Web in base al valore restituito.
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>
corrente LY sta tornando:
[object Object]
Ho anche cercato di rimetterla in un div con .text()
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
}
] }
favore qualcuno può dirmi che cosa ho fatto di sbagliato .
Grazie in anticipo!
Provate ad usare 'console.log (resp)', che cosa fa che danno. – MisterBla
Mostraci la risposta, quindi ti possiamo aiutare. – mguimard
Possiamo vedere il codice sorgente per la tua pagina 'demo.json'? E hai provato 'console.log (resp);'? –