나는 아래의 방법을 사용하여 문제 했어 :
자바 스크립트를
var dataParam='{"param":"1"}'; //or whatever data you may be sending or not sending
$.ajax({
type : "POST",
url : myHomeUrl + '/SendDataVoid',
contentType : "application/json; charset=utf-8",
data : dataParam,
datatype : "json",
}).done(function (data) {
alert('success');
}).fail(function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.getResponseHeader("error"));
});
당신이 보낼 수있을 수 있습니다 C#을
[WebMethod]
public static void SendDataVoid(string param)
{
try
{
//do stuff here
}
catch (Exception ex)
{
System.Web.Services.WebService wsError = new System.Web.Services.WebService();
wsError.Context.Response.StatusCode = 500;
wsError.Context.Response.AppendHeader("error", ex.Message);
}
}
실제 오류 msg back i 제네릭 "내부 서버"오류가 발생했습니다.
'WebMethod'는 더 이상 지원되지 않습니다. (http://johnwsaunders3.wordpress.com/2011/12/07/more-reasons-to-not-use-asmx-services-in-new-code/) Microsoft. REST 기반 서비스 [ASP.NET Web API] (http://www.asp.net/web-api)의 대체 기술을 살펴볼 수 있습니다. 그것은 더 깨끗한 모델을 가지고 있으며 Microsoft에 의해 지원됩니다. – mason