segunda-feira, 2 de junho de 2014

combo com Jquery+Ajax

HTML DE EXEMPLO

<table>
    <tr>
        <th>
            Gender
        </th>
        <td>
            <select id="ddlGender">
            </select>
        </td>
    </tr>
    <tr>
        <th>
            Name
        </th>
        <td>
            <select id="ddlName">
            </select>
        </td>
    </tr>
</table>

RETORNO VIA WEBSERVICE E APLICAÇÃO

$().ready(function() {
    $.ajax({
        type: "POST",
        url: "Default.aspx/Exemplo",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            $("#ddlGender").get(0).options.length = 0;
            $("#ddlGender").get(0).options[0] = new Option("Select gender", "-1");   
 
            $.each(msg.d, function(index, item) {
                $("#ddlGender").get(0).options[$("#ddlGender").get(0).options.length] = new Option(item.Display, item.Value);
            });
        },
        error: function() {
            alert("Failed to load genders");
        }
    });
});   

Nenhum comentário:

Postar um comentário