웹 메서드 EmailFormRequestHandler
에 아약스 게시를 만들고 있는데, 클라이언트 측에서 (방화 광구를 통해) 요청 상태가 200이지만 멈춤 지점에 도달하지 않았습니다 (첫 줄 webmethod의) 내 webmethod. json 매개 변수가 모두 object
이었지만 json을 deserialize하는 방식으로 모든 것을 문자열로 변경해야했습니다.json string을 webmethod에 매개 변수로 전달합니다.
JS :
function SubmitUserInformation($group) {
var data = ArrayPush($group);
$.ajax({
type: "POST",
url: "http://www.example.com/components/handlers/FormRequestHandler.aspx/EmailFormRequestHandler",
data: JSON.stringify(data), // returns {"to":"[email protected]","from":"[email protected]","message":"sdfasdf"}
dataType: 'json',
cache: false,
success: function (msg) {
if (msg) {
$('emailForm-content').hide();
$('emailForm-thankyou').show();
}
},
error: function (msg) {
form.data("validator").invalidate(msg);
}
});
}
영문 : 당신은 당신이 중단 점을 설정하려는 의미
[WebMethod]
public static bool EmailFormRequestHandler(string json)
{
var serializer = new JavaScriptSerializer(); //stop point set here
serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
dynamic obj = serializer.Deserialize(json, typeof(object));
try
{
MailMessage message = new MailMessage(
new MailAddress(obj.to),
new MailAddress(obj.from)
);
message.Subject = "email test";
message.Body = "email test body" + obj.message;
message.IsBodyHtml = true;
new SmtpClient(ConfigurationManager.AppSettings["smtpServer"]).Send(message);
return true;
}
catch (Exception e)
{
return false;
}
}
그래서 당신이 말하는 상태 코드는'200'하지만, 오류도 성공 콜백도 실행되지 않습니까? – Rafay
@ 3nigma correct – bflemi3