So many things wrong with that code...
Your
<select>
element has an ID of
ddl_type
, but your script tries to reference an element with the ID
ddltype
. Those are two completely different IDs.
You declare an array variable called
$duplicate
, but then use the undeclared variable
duplicate
for the rest of your function.
You call a jQuery method called
appennd
, which is not a standard method. I suspect you wanted to call
append
instead.
Your HTML has extra spaces between the attribute name and the equals sign.
You try to find the index of a function object in your array, rather than looking for the index of the value returned from the function.
The array wouldn't contain the value returned from the function either, since you push the entire
fldtype
string into the array.
You try to use an array of characters as the value of your
option
, rather than using an element from the array.
It's not entirely clear what you are trying to achieve with this code. But an initial clean-up would look something like this:
$.ajax({
type: 'GET',
url: '@Url.Action("GetWebApiLog")',
data: { id: $("#ddl_type").val() },
success: function(datas) {
const duplicate = [];
$("#ddl_type").empty().append($("<option/>"));
$.each(datas, function(i, data) {
const splitData = data.fldtype.split("-");
if (duplicate.indexOf(splitData[0]) === -1) {
$("#ddl_type").append($("<option/>").attr("value", splitData[0]).text(data.fldtype));
duplicate.push(splitData[0]);
}
});
}
});
If it still doesn't work, use your browser's developer tools to debug the script to see what the problem is.