我對jQuery和JavaScript非常陌生,但我想將電子郵件提交給我編寫的.NET Web服務。我已經用我的數據中的一些簡單值測試了Web服務,但是我希望能夠在完成一些客戶端和服務器端驗證之後提交整個表,以填充服務器端。使用jQuery.ajax()提交帶有.NET Web服務的HTML表格
這工作:
data: '{ strFrom: "[email protected]", to: "[email protected]", cc: "[email protected]", subject: "test subject", body: "test body" }'
但是,就像我說我有這個表我已經填充到表單回覆,當我做一個變種體= $(「#divSuccessDetails」)HTML(。 );並通過它而不是「測試體」我得到一個無效的對象響應。我測試過,我選擇表的結果,並沿着這一行是:
<table id="ctl00_ContentPlaceHolder1_tblSuccessDetails" class="successDetails" style="width:80%;">
<tbody><tr>
<td class="successHeading" colspan="2">
Reporting Category
</td>
</tr>
<tr>
<td>
<span id="ctl00_ContentPlaceHolder1_lblBilling">Billing Provider: <b></b></span>
</td>
<td rowspan="1">
<span id="ctl00_ContentPlaceHolder1_lblCategory">Reporting Category: </span></td>
</tr>
<tr>
我的Web服務的方法是這樣的:
public string Email(string strFrom, string to, string cc, string subject, string body) {
try
{
MailMessage objMail = new MailMessage();
MailAddress from = new MailAddress(strFrom);
objMail.From = from;
objMail.To.Add(to);
objMail.CC.Add(cc);
objMail.Subject = subject;
objMail.Body = body;
SmtpClient smtp = new SmtpClient("pobox.abc.edu");
smtp.Send(objMail);
return "{\"form\": { \"successful\": \"true\" }}";
}
catch (Exception ex)
{
return "{\"form\": { \"successful\": \"false\" }, {\"exception\": {\"ex\": \"" + ex.Message + "\" }}";
}
}
我收到錯誤消息是沿着這些線路:
"Invalid object passed in, ':' or '}' expected. (176): { strFrom: "[email protected]", to: "[email protected]", cc: "[email protected]", subject: "IDX Provider Form by IDX Provider Form by abcd", body: " <table id="ctl00_ContentPlaceHolder1_tblSuccessDetails" class="successDetails" style="width:80%;"> <tbody><tr> <td class="successHeading" colspan="2">
我只是希望在把它作爲一個字符串,因爲這是我收到的..我已經把大量的HTML中,我用一個emailobject之前,但字符串這是我第一次試圖通過AJAX傳遞它。
我在這裏看不到Web服務。有沒有'[WebMethod]'屬性丟失? –
是的抱歉,我沒有把所有東西放在一起,以保持它的小。 – Tony
那麼WebMethod在哪裏? –