I am trying to code a working stock ticker and am having a heck of a time finding more information on how to use JSONP data. I have googled the heck out of this only to find that what I am doing continually doesn’t work. Here is what I am trying to accomplish:
<script>
function quote_search(json) {
var symbol = document.getElementById("symbol");
var last = document.getElementById("last");
var exchange = document.getElementById("exchange");
var change = document.getElementById("change");
symbol.innerHTML = json.symbol;
last.innerHTML = json.last;
exchange.innerHTML = json.exchange;
change.innerHTML = json.change;
}
</script>
Please be easy… I am a complete noob when it comes to using JSON/JSONP and am definitely no JavaScript guru either. Any help would be greatly appreciated.
IMHO having a function with the same name as the object is not good.
Assuming the quote_search object exists when you try to get its properties, something like this should work
<script>
function show_quote(quote_search) {
var symbol = document.getElementById("symbol");
var last = document.getElementById("last");
var exchange = document.getElementById("exchange");
var change = document.getElementById("change");
symbol.innerHTML = quote_search.symbol;
last.innerHTML = quote_search.last;
exchange.innerHTML = quote_search.exchange;
change.innerHTML = quote_search.change;
}
</script>
Sorry, I took a closer look and noticed it isn’t returning an object, but a function call.
So you were closer to the solution than I was and I was misleading you
After some trial and error, this works for me (some name changes to avoid confusion and possible conflict)