ajax without query permission

0

I have a webservice in wcf in the link , I can consume it no problem in my iis location with ajax:

                                            View User         

      <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 ConsUsuario(){
        var value = $("#codUser").val();

        $.ajax({
        type: "GET",
        //url: "ServiceRestPub/ServiceUsuario.svc/ConsultarRegistroPorCodigo/" + value,
        url: "http://food-fast-com.web27.redehost.net/ServiceUsuario.svc/ConsultarRegistroPorCodigo/" + value,
        contentType: "application/json",
        dataType: "json",
        success: function (result) {
          var tabela = $("#datagrid");
                            var rows = "";
                            tabela.find("tbody td").remove();

                                rows += "<tr>";
                                rows += " <td>" + result.ConsultarRegistroPorCodigoResult.Codigo + "</td>";
                                rows += " <td>" + result.ConsultarRegistroPorCodigoResult.Login + "</td>";
                                rows += " <td>" + result.ConsultarRegistroPorCodigoResult.Nome+ "</td>";
                                rows += " <td> <input type='checkbox' /> </td>";
                                rows += "</tr>";

                tabela.html('<tbody>' + rows + '</tbody>');
            }
        });
    }
 </script>

However, when consuming the one from the link posted above I have the following return: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' link ' . I tried to put the following code in WebConfig:

 <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
        <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE" />-
      </customHeaders>
    </httpProtocol>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="false" />
  </system.webServer>

In my local iis it works, but when I upload to my server it gives the following error:

This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".

I talked to the support staff and he said that it is standard not to allow this type of implementation in webconfig.

How do I consume a webservice with ajax?

    
asked by anonymous 12.05.2017 / 05:30

1 answer

0

Remove the ContentType from the request and add:

 crossDomain: true,
 dataType: 'jsonp',

Follows:

$.ajax({
   type: "GET",
   url: "http://food-fast-com.web27.redehost.net/ServiceUsuario.svc/ConsultarRegistroPorCodigo/" + value,
   crossDomain: true,
   dataType: 'jsonp',
   success: function (result) { ... },
   error: function(data){ ... }
  

If you wish to force crossDomain request (such as JSONP) on the same   domain, set the value of crossDomain to true. This allows, for   example, server-side redirect to another domain

link

    
12.05.2017 / 12:56