Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Sonny Österlund
6,578 PointsAjax Jquery Json success problems
Hi I would love to get some help with a problem I have that I just can't solve because of my lack of knowledge I have first of all some html coding with a few radio buttons with a attached span to each:
<div id="output2">
<input type="radio" name="tid" value="1"><span class="green">Span 1</span>
<input type="radio" name="tid" value="2"><span class="green">Span 2</span>
<input type="radio" name="tid" value="3"><span class="green">Span 3</span>
<input type="radio" name="tid" value="4"><span class="green">Span 4</span>
<input type="radio" name="tid" value="5"><span class="green">Span 5</span>
</div>
I have an ajax request sending off a request to a php script the success part is empty here because this is where I have my problem I have no idea what to do here
$.ajax({
type: "POST",
url: "fetch_time.php",
data: "datum_id=" + datum_id,
beforeSend: function() {
$('#output2').html('<img src="#" alt="" width="24" height="24">');
},
success: function(json) {
});
I get a return value from the php script in the form of a json file that looks for example like this:
[{"tid_id":"4"},{"tid_id":"5"}]
What I want to do is to use these values from the json file the 4 and 5 and compare them to the value of the radio buttons, and IF the value from the json file is the same as the value on that specific radiobutton I want the radiobutton to be disabled and the class of the corresponding span to change from class="green" to class="red" OR just change visibility on the radiobutton and the span to none.
If anyone could help me out I would be very greatful
Sonny Österlund