I’m running Sitecore 6.4 and trying to get some data using ajax and webmethod in Sitecore. Everything is in a sublayout (user control)
This is the code that calls the webmethod:
$("#NextBanner").click(function () {
$.ajax({
type: "POST",
url: "/GetNext",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('success');
},
error: function (err) {
alert('error');
}
});
This is the webmethod, returns a string:
[WebMethod]
public static string GetNext()
{
return "Hello";
}
In a test project without using Sitecore I used “Default.aspx/GetNext” as the url for the ajax call but now obviously this doesn’t work, I get 404 not found error because of the url.
What should the url be? The sublayout path is: /layouts/sublayouts/test.ascx
Any recommendation on a different approach of achieving this?
Thanks,
T
Update
Thanks everybody for the answers.
I ended up creating a web service under website/sitecore/shell/webservices, not sure if that’s the right place to put the web service, any suggestions?
Thanks,
T
I created a folder under ‘Website’ and placed my web services there.