I have an application page (aspx) deployed in the _LAYOUTS
folder of MS SharePoint 2010.
I would like to call a method inside that page marked with the [WebMethod]
attribute using jQuery. I am using the following code on document.ready()
:
$("#btnOk").click(function () {
var theUrl = '/_layouts/MyProject/MyPage.aspx/MyMethod';
$.ajax({
type: "get",
dataType: "json",
url: theUrl,
data: {},
success: function (response) {
[...]
},
error: function (xhr, textStatus, errorThrown) {
[...]
}
});
});
This code unfortunately does not work. The problem is with the URL: in fact it works if I use an absolute URL like this
var theUrl = 'http://server/sites/xxx/_layouts/MyProject/MyPage.aspx/MyMethod';
How can I transform my path in an absolute one?