When clicking on a list item, does it go out of scope when going into the getJSON section where I want to go and get data from a database?
I have a list of items displaying colours. Each list item has an ID set to that of a SKU. When I click on a list item, it must go and get data from the database for that SKU and populate the contents on the page.
I was playing around with some code and for interest's sake I wanted to see if I could change the text of the clicked on list item. So after the JSON call is done, I tried to set the text, but nothing happened.
I get the sku of the clicked on list item like this:
var sku = this.id;
After I do the JSON call I tried to set the text of this clicked on list item like this:
this.text('sample text');
I even tried:
this.Text('sample text');
Here is my full JavaScript/jQuery code:
<script>
$(document).ready(function () {
$('.attributes li').click(function () {
var url = 'http://ift.tt/1H2fxo3';
var sku = this.id;
$.getJSON(url, { sku: sku }, function (data) {
// This does not work
this.Text('sample text');
});
});
});
</script>
Here is my HTML markup:
<ul class="list-inline attributes selectable">
<li id="sku0001">Blue</li>
<li id="sku0002">Green</li>
<li id="sku0003">Red</li>
<li id="sku0004">Yellow</li>
</ul>
When going into the getJSON section does the this go out of focus? Does the clicked on list item go out of scope?
Aucun commentaire:
Enregistrer un commentaire