I have real hard time in populating select box in asp.net using the jQuery ajax call. The value appears for second on submit button’s click event but then disappears, once the page gets refreshed. However this works fine with <input type="button">, but I don’t want to go that way.
function lodaStatedta()
{
var methodURL = "Default.aspx/LoadStates";
var parameters ="{}"; //"{'content':'" + $("#ContentTextarea").val() + "', 'autosave':'" + autosaveMode + "'}";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: methodURL,
data: parameters,
dataType: "json",
async: true,
success: function(data) {
var listItems = "";
var states = data.d;
$.each(states, function (item , index) {
//alert(item);
listItems += "<option value='" + index + "'>" + item + "</option>"
});
$('#mysselect').html(listItems);
},
error: function (result) {
}
});
}
and calling the method above on submit button click event.
I may be misunderstanding, but you’re using input/@type=submit as a button that isn’t supposed to submit the form, right? In that case, either place this to FORM tag:
or this at the end of your submit-btn’s onclick:
so, try that