I'm really sorry to be posting all day. I'm a total newbie with this coding. Basically, with the help of a lot of amazing people here, I'm setting up a JSON thingy for the first time. I'm trying to evaluate a list against an input. Here's sample data:
{
"
films": [{
"label": "34",
"value": "34",
"currently_streaming": "1",
"full_streaming_url": "http://www.url.com",
"url": "http://www.url.com"},
{
"label": "A Different Color",
"value": "A Different Color",
"currently_streaming": "1",
"full_streaming_url": "http://www.url.php",
"url": "http://www.url.com"}]
}
and here's my code. I finally got it, (thank you everyone!) to select the value portion that I wanted. I then tried to compare it in an if/else statement, and it's doing weird things. First, it seems to be pulling more values than actually exist on the file, but I'm not completely sure about that. Secondly, however, it seems to be not comparing values, but setting one the value I'm iterating through equal to another value! I don't understand!
var test = "34x25x36";
$(document).ready(function () {
$.ajax({
dataType: 'json',
beforeSend: function () {
console.log('Before Ajax Request Starts !!');
},
success: function (data) {
console.log(data);
alert("Edddddddd");
$.each(data.films, function (i, object) {
$.each(object, function (property, value) {
//alert(property + "=" + value);
for (i = 0; i < data.films.length; i++) {
var theFilm = (data.films[i].value);
if (theFilm == test) {
document.write(theFilm);
document.write(test + "<br>");
} else {}
}
});
});
},
error: function (jqXHR, textStatus, errorThrown) {
alert("Error occurred: " + errorThrown);
},
beforeSend: function () {
console.log('Ajax Request Complete !!');
},
url: 'test.php'
});
});
EDIT
When I do have something in the else{ } section, it seems to run the whole thing multiple times, judging correctly when doesn't match, but then it seems to run again, running the text for the one match and then a bunch of "not match" text. When there is nothing in the else{} section, it seems to set the value of theFilm = test . Help!
". I don't know if this would work in JSON but it wouldn't in regular JS.