我正在尝试通过ajax传递多个值,这些值存储在jquery变量中,并且想要在webservice构造函数方法中检索这些值。 jquery Ajax的代码
$("#formsubmit").click(function(){
var obj = { name: $("#contact_name").val(), email: $("#contact_email").val(),phone:$("#contact_phone").val(),
month:$("#rfp_requestmonth").val(),phone:$("#contact_phone").val(),month:$("#rfp_requestmonth").val,
date:$("#rfp_requestdate").val(),year:$("#rfp_requestyear").val(),time:$("#requested_time").val,
guest:$("#number_guests").val(),comments:$("#contact_comments").val()};
$.ajax({
type:$('.rfpform').attr('method'),
url: "Thankyou.asmx/ThanksMail",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(obj),
dataType: "json",
success: function (response) {
var names = response.d;
alert(names);
location.assign(/^http/i.test(nextWebPageId) ? nextWebPageId : (location.protocol + "//" + location.hostname + "/?pg=" + nextWebPageId));
},
failure: function (response) {
alert(response.d);
}
});
webservice方法,我想要检索值。
public Thankyou()
{
MailMessage o = new MailMessage();
SmtpClient smtpobj = new SmtpClient("ervices.com", 38);
smtpobj.EnableSsl = false;
o.From = new MailAddress("esh_p07@hotmail.com");
o.To.Add("esh07@gmail.com");
o.Subject = "The Culver Hotel Event Inquiry Form";
o.IsBodyHtml = true;
string htmlBody;
htmlBody = "You have received an email via the<b>[ver Hotel<b>Event Inquiry form.<br/><b>From:[#text:contact_name#]</b><br/><b>Phone:</b><br/><b>Requested Date:</b><br/>;<b>Requested Time:</b><br/><b>Number of Guests:</b><br/><b>Comments:</b>";
o.Body = htmlBody;
smtpobj.Send(o);
}
我希望变量'obj'中存储的值填充在webmethod构造函数的“htmlBody”部分的相应字段中。非常感谢。