Reputation: 71
I have the following code: which returns uncaught syntax error :. If I remove the dataType i get no errors but i also get no data?
function myfunc() {
var value = $("#firstselect").val();
$.get("contactlist.php",
{SEARCH_PARAM: value },
dataType: "json",
function(data) {
var options = '<option value="">Select one...</option>';
for(var i = 0; i < data.length; i++) {
options += '<option value="' + data[i].id +'">'+data[i].name+'</option>';
}
$("#secondselect").html(options);
}
);
}
Upvotes: 0
Views: 331
Reputation: 1060
you have the parameters in a wrong order. DataType has to be the last
try:
function myfunc() {
var value = $("#firstselect").val();
$.get("contactlist.php",
{SEARCH_PARAM: value }
function(data) {
var options = '<option value="">Select one...</option>';
for(var i = 0; i < data.length; i++) {
options += '<option value="' + data[i].id +'">'+data[i].name+'</option>';
}
$("#secondselect").html(options);
},
"json"
);
}
Upvotes: 0
Reputation: 19635
Your success function needs to come before data type, and the data type should just be a string literal, not a named value:
function myfunc() {
var value = $("#firstselect").val();
$.get("contactlist.php",
{SEARCH_PARAM: value },
function(data) {
var options = '<option value="">Select one...</option>';
for(var i = 0; i < data.length; i++) {
options += '<option value="' + data[i].id +'">'+data[i].name+'</option>';
}
$("#secondselect").html(options);
},
"json"
);
}
Upvotes: 6