下面的代码总是因为400个错误请求而失败

本文关键字:错误 请求 失败 400个 是因为 代码 | 更新日期: 2023-09-27 17:49:39

    function SendEditCommand()
    {
        jQuery.ajax({
            url: 'http://localhost:15478/Service.svc/GetTest',
            type: 'GET',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function () {
                alert('success');
            },
            error: function(request, status, error) {
                alert(error);
            }
        });
    }
    jQuery(document).ready(function () {
        SendEditCommand();
    });
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <connectionStrings>
        <add name="Entities" connectionString="metadata=res://*/Data.TechieCMS.csdl|res://*/Data.TechieCMS.ssdl|res://*/Data.TechieCMS.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=localhost'mssql2008;Initial Catalog=TechieCMS;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>
    <system.serviceModel>
        <services>
            <service name="DefaultService" behaviorConfiguration="DefaultServiceBehavior">
                <endpoint address="" binding="webHttpBinding" contract="Techie.CMS.Business.ContentProvider" behaviorConfiguration="DefaultEndpointBehavior" />
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <endpointBehaviors>
                <behavior name="DefaultEndpointBehavior">
                    <enableWebScript />
                </behavior>
            </endpointBehaviors>
            <serviceBehaviors>
                <behavior name="DefaultServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    </system.serviceModel>
</configuration>
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ContentProvider
    {
        [OperationContract]
        [WebGet()]
        public string GetTest()
        {
            return "Test";
        }
    }

下面的代码总是因为400个错误请求而失败

我猜它不喜欢URL中的端口。其他的都是正确的。你在用IE吗?它能与其他浏览器一起工作吗?其他有同样问题的人一直在使用IE,它在Firefox上也能工作。

也许尝试添加一个数据变量并将其更改为POST?有人说这就解决了。

感谢大家的回答,它们确实是相关的,并且是拼图的一部分。关键问题是