使用jquery ajax调用c#webservice

时间:2016-02-29 13:15:20

标签: javascript c# jquery ajax web-services

当我尝试使用jquery ajax调用c#webservice时,我得到Internal Server Error,如果我直接从浏览器调用它,我会收到以下错误

System.InvalidOperationException: newDonor 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)

以下是网络方法

[WebMethod]
public void newDonor(localDonor donor)
{
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));

    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
    CloudTable table = tableClient.GetTableReference("donors");

    table.CreateIfNotExists();
    Donor newDonor = new Donor(donor.FullName, donor.Mobile);

    TableOperation insertOperation = TableOperation.Insert(newDonor);
    table.Execute(insertOperation);}

以下是jquery的ajax方法

  var userInput = {
                FullName: "Lakshman NEW",
                Mobile: "1122004455"
            };

        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "addDonor.asmx/newDonor",
            data: JSON.stringify(userInput),
            dataType: "json",
            error: function (error) {

                alert(error.toString());
                }
            });

可能是什么错误,一切似乎都很好...... ???

0 个答案:

没有答案