0

下面是我需要使用 ajax 访问的 web 方法:

 [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string CallConfiguredWebService(String projectID,String workType,String Page,String Action,String webServiceName,Object[] arguments)
        {}

我尝试使用以下代码从脚本访问它。

var args = [2];
            args[0] = "Hai";
            args[1] = "Saranya!!";

            $.ajax({
                url: "../../Services/ValidationService.asmx/CallConfiguredWebService?",
                method: "POST",
                data: JSON.stringify({ projectID: '302',workType: 'LFAT',Page: 'Create', Action: 'Create', webServiceName: 'WebService195174',arguments: args}),
                dataType: 'json',
                contentType: 'application/json',
                success: fnsuccesscallback,
                error: fnerrorcallback
            });

我收到以下错误:

500 - Internal server error No service found at /Services/ValidationService.asmx.

我很确定网址是正确的。

我从类似的帖子中了解到,这可能是因为 ajax 调用中的参数不匹配。

我无法弄清楚我的代码中的确切错误是什么。

也试过用JSON.stringify

请帮助您的专业知识。

更新:

重新部署 Web 应用程序后,ajax 调用开始工作。

4

2 回答 2

1

只要服务目录位于 Web 应用程序的根目录,您就可以将您的 url 从“../../Services/ValidationService.asmx/CallConfiguredWebService”更改为“/Services/ValidationService.asmx/CallConfiguredWebService”。您永远不应该使用“../”,一个简单的“/”将解析从网站根目录开始的任何 url

于 2013-11-05T09:04:58.577 回答
0

ajax 调用在重新部署 Web 应用程序后开始工作,无需对代码进行任何更改。

于 2013-11-05T07:20:09.277 回答