I have an input of type date in HTML5 to select the date and from the date fill a select with options with the available schedule of the database for that day. For that I activate the event onChange of the input type date and I use ajax to call a method [WebMethod] and json to fill the select type option but it throws me an error object object object
Function ajax json
function ShowCurrentTime() {
// armo el objeto que servira de parametro, para ello utilizo una libreria de JSON
//este parametro mapeara con el definido en el web service
var params = new Object();
params.dia = $("#<%=fechacita.ClientID%>").val();
params = JSON.stringify(params);
$.ajax({
type: "POST",
url: "/citas5.aspx/GetCurrentTime",
data: params,
//data: '{name: "' + $("#<%=fechacita.ClientID%>")[0].value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
//$("#<%=hora1.ClientID%>").change(function () {
// alert("Ha seleccionado: " + $("#<%=hora1.ClientID%> :selected").text());
// });
}
function OnSuccess(response) {
//quito los options que pudiera tener previamente el combo
$("#<%=hora1.ClientID%>").html("");
alert(response.d);
//recorro cada item que devuelve el servicio web y lo añado como un opcion
$.each(result.d, function () {
$("#<%=hora1.ClientID%>").append($("<option></option>").attr("value", this.idhoras).text(this.horas))
});
}
HTML5 CALENDAR input type date
<input id="fechacita" type="date" name="fechacita1" onchange = "ShowCurrentTime()" autopostback="False" placeholder="Ingresa tu fecha" required="" runat="server"/>
combobox select tipo option
<select id="hora1" type="option" value="1" name="hora" runat="server" placeholder="Seleccione Tipo de Consulta" required=""/>
C#
[WebMethod]
public static List<CiudadEntity> GetCurrentTime(string dia)
{
var query = from item in GetPaises().AsEnumerable()
where Convert.ToString(item["time"]) != dia
select new CiudadEntity
{
idhoras = Convert.ToInt32(item["idtime"]),
horas = Convert.ToString(item["time"])
//descripcion = Convert.ToString(item["Ciudad"])
};
return query.ToList<CiudadEntity>();
}