I'm getting this error on my sharepoint web application (I'm calling my own web method through ajax on my own user control) while accessing it from another computer and I'm getting this error: “{“Message”:”There was an error processing the request.”,”StackTrace”:”",”ExceptionType”:”"}”
I've read that I need to install ASP.NET AJAX 1.0 on my MOSS 2007 Server to get this to work. Is it true?
Thanks
Edit:
Here's my ajax call:
var Item = {
emailSubject: jEmailSubject,
emailBody: jEmailBody,
userName: jUserName
};
$.ajax({
type: "POST",
url: "/_layouts/WebPartPages/qadrs-webservicepage.aspx/SendEmailToAdmin",
data: JSON.stringify(Item),
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function(error) {
alert(error.responseText);
return false;
},
success: function(response) {
if (response.d == "Success") {
alert('Email Sent to Administrator');
$('#<%=txbEmailSubject.ClientID %>').val('');
$('#<%=txtbEmailBody.ClientID %>').val('');
window.location = $('#<%=hdnUrlReferrer.ClientID %>').val();
}
else if (response.d == "NoEmailAddress") {
alert('No email address defined for admin users / user group admin is not configured in web config file. Email not sent.');
return false;
}
else if (response.d == "Error") {
alert('Error while trying to send email to admin.');
return false;
}
}
});
My Web Method:
public string SendEmailToAdmin(string subject, string body, string userName, int groupId)
{
string returnMessage = string.Empty;
string adminEmailAddresses = string.Empty;
int rowCounter = 0;
string fromEmail = string.Empty;
string fromName = string.Empty;
DataSet ds = UserDAL.GetInstance().GetAllUserEmailByUserGroupId(groupId, Common.GetInstance().StripDomain(userName), ConnectionString(""));
try
{
foreach (DataRow item in ds.Tables[0].Rows)
{
fromEmail = item["user_email_address"].ToString();
fromName = item["user_title"].ToString();
}
foreach (DataRow item in ds.Tables[1].Rows)
{
if (rowCounter == 0) adminEmailAddresses += item["user_email_address"].ToString();
else adminEmailAddresses += "," + item["user_email_address"].ToString();
rowCounter++;
}
if (rowCounter == 0) returnMessage = "NoEmailAddress";
else
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(fromEmail, fromName);
mail.To.Add(adminEmailAddresses);
mail.IsBodyHtml = true;
mail.Subject = subject;
string newBody = string.Empty;
newBody += "<html><head></head><body>" + body.Replace("\n", "<br />") + "</body></html>";
mail.Body = newBody;
try
{
SmtpClient mailClient = new SmtpClient();
mailClient.Send(mail);
returnMessage = "Success";
}
catch (Exception ex)
{
returnMessage = "Error";
throw ex;
}
}
}
catch (Exception exc)
{
}
return returnMessage;
}