You cant return the value from
Success
callback function of
ajax call
, instead you should write all your logic inside success callback.
function addSelect(divname, columname, dropid, tablename) {
var newDiv = document.createElement('div');
var html = '<select>'
var obj = {};
obj.coluname = cn;
obj.tablename = tablename;
$.ajax({
url: "webmethod.aspx/dropdownbine",
data: JSON.stringify(obj),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (r) {
var result = r.d;
for (i = 0; i < result.length; i++)
html += "<option value='" + result[i] + "'>" + result[i] + "</option>";
html += '</select>';
newDiv.innerHTML = html;
document.getElementById(divname).appendChild(newDiv);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert('Got an Error ');
}
});
}