Can anyone suggest why this isn't loading the autocomplete data? If i hardcode the URL in the ajax call, it works, but not with my code to alter the url source? I'm unsure why it wouldn't work. If you want to look at the page as a whole, the hardcoded version is:here
var starterSearchData;
$(function() {
var destination;
elementVal = $("input[name=radio]"); //note returns array of radio button elements
if (elementVal[0].checked){
destination= "http://ift.tt/2hU3guN",
}
if (elementVal[0].checked){
destination= "http://ift.tt/2ktLRxW",
}
//Starter Autocomplete (Spanish)
var starterSearchData;
$(function() {
$.ajax({
url: destination,
dataType: "jsonp",
async: false,
success: function(data) {
starterSearchData = $.map(data, function(item) {
if (item.course == "starter")
return item.name;
return item.price;
});
EnableAutoComplete();
},
error: function(xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
alert(err.Message);
}
});
function EnableAutoComplete() {
$("#starter").autocomplete({
source: starterSearchData,
minLength: 2,
delay: 010
});
}
});
Radio button:
<div id="radio">
<input type="radio" id="radio1" name="radio"><label for="radio1">Spanish</label>
<input type="radio" id="radio3" name="radio"><label for="radio3">Italian</label>
</div>
Aucun commentaire:
Enregistrer un commentaire