consume the webservice in WCF with ajax

Asked

Viewed 90 times

1

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form id="form1">
    <div class="jumbotron">
        <input type="text" id="codUser"/>
        <button onclick="ConsUsuario(); return false;">Consulta Usuario</button>
    </div>
</form>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
    function ConsUsuario(){
        var value = $("#codUser").val();

        $.ajax({
        url: "http:/food-fast-com.web27.redehost.net/ServiceUsuario.svc/ConsultarRegistroPorCodigo",
        type: "GET",
        data: JSON.stringify(value),
        dataType: "json",
        contentType: "application/json",
        success: function (result) {
            console.info(result);
            }
        });
    }
 </script>

of the error Failed to load resource: the server responded with a status of 404 , as if it did not find the webservice path, but in soapUI it works blz.

  • Try using the script this way by changing its parameter passage to the URL. function ConsUsuario(){&#xA; var value = $("#codUser").val();&#xA;&#xA; $.ajax({&#xA; url: "http://food-fast-com.web27.redehost.net/ServiceUsuario.svc/ConsultarRegistroPorCodigo/" + value,&#xA; type: "GET",&#xA; dataType: "json",&#xA; contentType: "application/json",&#xA; success: function (result) {&#xA; console.info(result);&#xA; }&#xA; });&#xA; }

  • Leandro worked, however it presented another message 'Method not alowed', but in the header it is correct:

  • Leandro did not give error however the return of the console was : 'Object {Query {"Consultationregister":{"Code":2,"Code":1,"Login":"ednilson1","Name":"Ednilson","Registration":true,"Password":"123456","Type":"D"}}, I saw that the server is not allowed to (*), so I tested on localhost by the browser with the URL: http://localhost/Servicerestpub/Serviceusuario.svc/Consultarregistroporcodigo/2 which is permitted for all methods

  • Well, the return of your webservice is correct. Now you just need to use your object, I believe within your method Success you can access the returned object by following the example: success: function (result){alert(result.ConsultarRegistroPorCodigoResult.Codigo);}

  • worked @Leandroaraujo, thanks friend for the help!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.