使用JQuery Ajax调用WCF REST服务并不适用于所有浏览器(chrome除外)

时间:2013-06-05 14:47:57

标签: wcf jquery jquery-mobile wcf-data-services wcf-rest

使用jquery-ajax调用wcf rest服务完全适用于chrome,但我在mozila中没有得到相同的结果,即等等, 所以请找到以下代码

这是网络配置...

<?xml version="1.0"?>
<configuration>
<appSettings configSource="appsettings.config"/>
<connectionStrings/>
<system.web>
<compilation targetFramework="4.0" debug="true"/>
<authentication mode="Windows"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
<defaultDocument>
  <files>
    <remove value="Default.htm"/>
    <remove value="Default.asp"/>
    <remove value="index.htm"/>
    <remove value="index.html"/>
    <remove value="iisstart.htm"/>
    <remove value="default.aspx"/>
    <add value="DataSync.svc"/>
  </files>
</defaultDocument>
<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*"/>
    <add name="Access-Control-Allow-Headers" value="Content-Type"/>
  </customHeaders>
</httpProtocol>
</system.webServer>
<system.serviceModel>
<services>
  <service name="TonightRoomsSynchronization.DataSync"    behaviorConfiguration="jsonServiceBehaviour">        
    <endpoint address="JSON" binding="webHttpBinding"  contract="TonightRoomsSynchronization.IDataSync" behaviorConfiguration="web" bindingConfiguration="StreamedRequestWebBinding"/>         
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
  </service>

</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="jsonServiceBehaviour">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <webHttpBinding>
    <binding name="StreamedRequestWebBinding"  crossDomainScriptAccessEnabled="true" bypassProxyOnLocal="true" useDefaultWebProxy="false" hostNameComparisonMode="WeakWildcard" sendTimeout="10:15:00" openTimeout="10:15:00" receiveTimeout="10:15:00" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="StreamedRequest">
      <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
    </binding>
  </webHttpBinding>
  <wsHttpBinding>
    <binding name="NewBinding0" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="false" maxBufferPoolSize="524288000" maxReceivedMessageSize="655360000" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
    </binding>
  </wsHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
</configuration>'

和HTML页面中的ajax调用如下..

  jQuery.support.cors = true

    function AssignValue() {
        debugger;
        Type= "POST";          
         Url = "http://ipaddress/TestTonightRoomsSynchronization/DataSync.svc/JSON/login/" + $("#txtUsername").val() + "/" + $("#txtPassword").val();           
        Data = '{}';
        DataType = "JSON";
        ContentType = "application/json; charset=UTF-8";
        ProcessData = true;
        CallService();
    }  

    function CallService() {
        $.ajax({
            type: Type,
            data: Data,
            dataType: DataType,
            processData: ProcessData,
            url: Url,
            contentType: ContentType,
            crossDomain: true,
            success: function (jsonObj) {                 
               alert('success');
            },
            error: function (response) {
                alert('Error while sending the request');
            }
        });
    }'

0 个答案:

没有答案