consume asmx with ajax (outside the webservice layer)

0

In my solution I have several layers and one of them is the webservice, all pages that conserve the webservice and are in the webservice layer work, but I put it in another layer of the error in javascript.

         

    <table border="0">
        <tr>
            <td>
                Emp:
            </td>
            <td>
                <input id="txtEmp" type="text" />
            </td>
        </tr>
        <tr>
            <td>
                User:
            </td>
            <td>
                <input id="txtUser" type="text" />
            </td>
        </tr>
        <tr>
            <td>
                Pass:
            </td>
            <td>
                <input id="txtPass" type="text" />
            </td>
        </tr>
        <tr>
            <td>
                <!--<button id="btnSubmit1" value="button" type="submit"></button>-->
                <input id="btnSubmit1" type="button" value="button" />
            </td>
        </tr>
    </table>
    <div><table id="datagrid"></table></div>
</form>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script><scripttype="text/javascript">
    $(function () {
        $("[id*=btnSubmit1]").click(function () {
            var emp = $.trim($("[id*=txtEmp]").val());
            var user = $.trim($("[id*=txtUser]").val());
            var pass = $.trim($("[id*=txtPass]").val());
            $.ajax({
                type: "POST",
                url: "Service.asmx/SELECT_ALL_CATEGORIAS",
                data: "{ EMP_ID: " + emp + ", UserName: '" + user + "', Password: '" + pass + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    debugger;
                    if (!data) {
                        alert('Fornecedor não encontrado. Por favor verifique e tente novamente.');
                    } else {
                        var tabela = $("#datagrid");
                        var rows = "";
                        tabela.find("tbody td").remove();
                       // var myData = data.d;
                        var myData = JSON.parse(data.d);
                        for (var i = 0; i < myData.length; i++) {
                            var obj = myData[i];

                            rows += "<tr>";
                            rows += " <td>" + obj.id + "</td>";
                            rows += " <td>" + obj.descricao + "</td>";
                            rows += " <td>" + obj.filial_id + "</td>";
                            rows += " <td> <input type='checkbox' /> </td>";
                            rows += "</tr>";
                        }

                       // tabela.find("tbody").html(rows);
                        tabela.html('<tbody>' + rows + '</tbody>');
                    }
                },
                error: function (data) {
                    debugger;
                    alert('Error');
                }
            });
            return false;
        });
    });
</script>

The layers I want to consume the webservice are using the Cordova framework.

    
asked by anonymous 20.04.2017 / 12:27

0 answers