Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从jQuery ajax调用WebMethod时出现内部服务器错误,Web服务方法无效_Jquery_Asp.net_Ajax_Web Services_Webmethod - Fatal编程技术网

从jQuery ajax调用WebMethod时出现内部服务器错误,Web服务方法无效

从jQuery ajax调用WebMethod时出现内部服务器错误,Web服务方法无效,jquery,asp.net,ajax,web-services,webmethod,Jquery,Asp.net,Ajax,Web Services,Webmethod,我试图在GetPlaform()javascript函数中使用ajax调用GetPlatformNames()webmethod。 但是,ajax调用永远不会成功。 在错误警报中,我收到“内部服务器错误”消息 我使用firebug并在错误中的警报上放置了一个断点。request.ResponseText声明如下: System.InvalidOperationException: GetPlatformNames Web Service method name is not valid. a

我试图在GetPlaform()javascript函数中使用ajax调用GetPlatformNames()webmethod。
但是,ajax调用永远不会成功。
在错误警报中,我收到“内部服务器错误”消息
我使用firebug并在错误中的警报上放置了一个断点。request.ResponseText声明如下:

 System.InvalidOperationException: GetPlatformNames Web Service method name is not valid.
 at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
 at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, 
  HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing).
这是我正在使用的代码
我正在使用Visual Studio 2012
我正在使用内置的IIS

    namespace XYZ
    {
//// <summary>
/// Summary description for Platform
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
[System.Web.Script.Services.ScriptService]
public class Platform : System.Web.Services.WebService
{
    [WebMethod]        
    public static string GetPlatformNames()
    {
        var result ="Hello World";
        return result;
    }
    [WebMethod]
    public static string GetServerTimeString()
    {
        return "Current Server Time: " + DateTime.Now.ToString();
    }
    [WebMethod]
    public static void AddaPlatform(string platforName)
    {
        //Code to insert into database
    }
}   
  }

function GetPlatforms() {  
var param = '{platformName:"'+$("#platformNameInputTextBoxId").val()+'"}';
$.ajax({
    type: 'POST',
    url: 'Platform.asmx/GetPlatformNames',
    statusCode: {
        404: function () {
            alert('Could not contact server.');
        },
        500: function () {
            alert('A server-side error has occurred.');
        }
    },
    success: function (data) {
        alert(data);
    },
    error: function(request,status,error) {
        alert(request.statusText);
    }
});
}
名称空间XYZ
{
//// 
///平台概要说明
/// 
[WebService(命名空间=”http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//要允许使用ASP.NET AJAX从脚本调用此Web服务,请取消注释以下行。
[System.Web.Script.Services.ScriptService]
公共类平台:System.Web.Services.WebService
{
[网络方法]
公共静态字符串GetPlatformNames()
{
var result=“你好世界”;
返回结果;
}
[网络方法]
公共静态字符串GetServerTimeString()
{
返回“当前服务器时间:”+DateTime.Now.ToString();
}
[网络方法]
公共静态void AddaPlatform(字符串platforName)
{
//要插入到数据库中的代码
}
}   
}
函数GetPlatforms(){
var param='{platformName:'+$(“#platformnameinputExtBoxId”).val()+'''}';
$.ajax({
键入:“POST”,
url:'Platform.asmx/GetPlatformNames',
状态代码:{
404:函数(){
警报('无法联系服务器');
},
500:函数(){
警报('发生服务器端错误');
}
},
成功:功能(数据){
警报(数据);
},
错误:功能(请求、状态、错误){
警报(请求状态文本);
}
});
}

请从正在调用的web方法中删除
static
关键字。然后就可以了。

它们是在同一个文件夹中吗这已经成功了,但是我看到了几个静态的例子有什么区别?jquery ajax的非静态函数调用和PageMethods的static函数调用。