• WCF Restful JQuery 跨域解决方法


    <?xml version="1.0"?>
    
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    
    <configuration>
      <connectionStrings>
        <add name="BIEntities" connectionString="metadata=res://*/BI.csdl|res://*/BI.ssdl|res://*/BI.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=BI;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
      <system.web>
          <compilation debug="true" targetFramework="4.0" />
          <authentication mode="Forms">
            <forms loginUrl="~/Account/LogOn" timeout="2880" />
          </authentication>
        <customErrors mode="RemoteOnly"/>
      </system.web>
      <system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
        <standardEndpoints>
          <webHttpEndpoint>
            <standardEndpoint crossDomainScriptAccessEnabled="true"/>
          </webHttpEndpoint>
        </standardEndpoints>
        <bindings>
          <webHttpBinding>
            <binding crossDomainScriptAccessEnabled="true" />
          </webHttpBinding>
        </bindings>
        <services>
          <service name="Service.BIService" behaviorConfiguration="ServiceBehavior">
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            <endpoint kind="webHttpEndpoint" contract="Service.IBIService" behaviorConfiguration="HelpBehavior" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="ServiceBehavior">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
            <behavior name="">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="HelpBehavior">
              <webHttp helpEnabled="true" />
            </behavior>
          </endpointBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>

    注意: help无法显示肯定是配置错误,上面的配置中一处是服务名称,一处是接口名称。

    <script type="text/javascript">
            $(function () {
                $(function () {
                    $.ajax({
                        type: "get",
                        url: http://server:88/KendoUI/ServiceHost/BIService.svc/InvoiceDelinquencyDistributionData,
                        dataType: "jsonp",
                        success: function (data) {
                            alert("ok");
                        }
                    });
                });
            });
        </script>
  • 相关阅读:
    Vue的响应式
    让html上两个元素在一行显示
    linux的<<命令
    http-only,withCredentials
    axios跨域请求时 withCredentials:true 表示request携带cookie
    异步代码async await阻塞进程的误区——await的是Promise的resolve而不是语句块的执行结束
    理解状态机
    关于express返回值的问题
    axios基本的get/post请求使用方法
    【转】 前端笔记之Vue(四)UI组件库&amp;Vuex&amp;虚拟服务器初识
  • 原文地址:https://www.cnblogs.com/nanfei/p/3941589.html
Copyright © 2020-2023  润新知