Javascript 从.Net中对SOAP web方法的Ajax调用中获取500服务器错误

Javascript 从.Net中对SOAP web方法的Ajax调用中获取500服务器错误,javascript,c#,.net,ajax,soap,Javascript,C#,.net,Ajax,Soap,我使用ajax进行了两个不同的异步调用。这两种方法都是以相同的方式完成的,但其中一种方法具有web方法的参数。链接是正确的,当我跟随它时,我在浏览器中得到了正确的返回,但我只是不断得到一个Server500错误。有什么想法吗? 一个没有参数也可以正常工作,下面是JS/jQuery代码,因为我有点确定它不在C#端: 函数CatChanged(){ var strA=$('#ddlcontegory').val(); $.ajax({ url:encodeURI('https://localhost

我使用ajax进行了两个不同的异步调用。这两种方法都是以相同的方式完成的,但其中一种方法具有web方法的参数。链接是正确的,当我跟随它时,我在浏览器中得到了正确的返回,但我只是不断得到一个Server500错误。有什么想法吗? 一个没有参数也可以正常工作,下面是JS/jQuery代码,因为我有点确定它不在C#端:

函数CatChanged(){
var strA=$('#ddlcontegory').val();
$.ajax({
url:encodeURI('https://localhost:44380/WebService1.asmx/GetProducts?category=“+strA),

数据:“好吧,如果我理解正确的话。当你用浏览器访问URL时,结果很好。但是当你进行ajax调用时,你会遇到麻烦

我从代码中注意到的一点是,您正在使用ajax调用执行POST请求,但方法都是GET。请尝试更改ajax调用中的类型以获取

例如

函数CatChanged(){
var strA=$('#ddlcontegory').val();
$.ajax({
url:encodeURI('https://localhost:44380/WebService1.asmx/GetProducts?category=“+strA),

数据:“是的,对不起,自从我开始尝试调试以来,我似乎已经改变了100次。如果我仍然有问题,我会用我再次尝试的结果更新我的问题。谢谢!!
function CatChanged() {
    var strA = $('#ddlCategory').val();
    $.ajax({
        url: encodeURI('https://localhost:44380/WebService1.asmx/GetProducts?category=' + strA),
        data: '<soap: Envelope xmlns: xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns: xsd="http://www.w3.org/2001/XMLSchema" xmlns: soap="http://schemas.xmlsoap.org/soap/envelope/%22%3E<soap: Body><xmlns="http://tempuri.org/" /></soap: Body></soap: Envelope >',
        type: 'POST',
        contentType: "text/xml",
        dataType: "text/xml",
        success: function (response) {
           alert(response.responseText);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert("ERROR!!");
            alert(xhr.status);
            alert(thrownError);
        }
    });
}
[WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string GetCategories()
        {
            Catalog cat = new Catalog();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            return jss.Serialize(cat.categories);
        }

        [WebMethod]
        public string GetProducts(string category)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            Catalog cat = new Catalog();
            List<string> retList = new List<string>();
            switch (category)
            {
                case "Electronics":
                    foreach (Product product in cat.electronicProducts)
                    {
                        retList.Add(product.itemName);
                    }
                    return jss.Serialize(retList);
                case "Apparel":
                    foreach (Product product in cat.apparelProducts)
                    {
                        retList.Add(product.itemName);
                    }
                    return jss.Serialize(retList);
                case "Food and Drink":
                    foreach (Product product in cat.electronicProducts)
                    {
                        retList.Add(product.itemName);
                    }
                    return jss.Serialize(retList);
                default:
                    foreach (Product product in cat.electronicProducts)
                    {
                        retList.Add(product.itemName);
                    }
                    return jss.Serialize(retList);
            }
        }
function CatChanged() {
    var strA = $('#ddlCategory').val();
    $.ajax({
        url: encodeURI('https://localhost:44380/WebService1.asmx/GetProducts?category=' + strA),
        data: '<soap: Envelope xmlns: xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns: xsd="http://www.w3.org/2001/XMLSchema" xmlns: soap="http://schemas.xmlsoap.org/soap/envelope/%22%3E<soap: Body><xmlns="http://tempuri.org/" /></soap: Body></soap: Envelope >',
        type: 'GET', // <-- Changed from POST to GET
        contentType: "text/xml",
        dataType: "text/xml",
        success: function (response) {
           alert(response.responseText);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert("ERROR!!");
            alert(xhr.status);
            alert(thrownError);
        }
    });
}