Accessing WebMethod in UserControl via AJAX
Hi,
I'm trying to do Newsletter Signup List. I want to add new e-mail address via ajax to my module but i cannot access to webmethod under my custom user control. Anyone can help me?
Ajax code:
$(function ()
$('input[type=submit][id$=btnSubscribe]').click(function ()
var Email = $('#<%=txtEmail.ClientID%>').val().trim();
if (Email != "")
$.ajax(
type: "POST",
url: "../../Widgets/ucNewsletterSignup.ascx/AddNewsletter",
data: "'Email': '" + Email + "'",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg)
var array = msg.d;
alert("başarılı");
);
else
return false;
);
[WebMethod]
public static void AddNewsletter(string Email)
DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
Type newslettermoduleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.NewsletterModule.Newslettermodule");
DynamicContent newslettermoduleItem = dynamicModuleManager.CreateDataItem(newslettermoduleType);
newslettermoduleItem.SetValue("Email", Email);
newslettermoduleItem.SetString("UrlName", "");
newslettermoduleItem.SetValue("Owner", SecurityManager.GetCurrentUserId());
newslettermoduleItem.SetValue("PublicationDate", DateTime.Now);
newslettermoduleItem.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName, "Draft");
dynamicModuleManager.SaveChanges();
What does firebug tell you?...what's happening, can we see a screenshot of the expanded item in the console tab?
Easy (more elegant) fix is to just leverage the SF WCF framework, it's WAY easier than you think it is
http://www.sitefinitysteve.com/blog/code/2012/03/16/simple-wcf-by-sitefinity
Hi Steve,
Console returns me that error
Hi Cem,
The problem is most likely coming from some authorization issues, as the actual call is understood but not allowed. There are several articles which can help you on the topic:
forums.asp.net/.../1
stackoverflow.com/.../using-jquery-to-call-a-webmethod
All the best,
Victor Velev
the Telerik team