Json and WebMethod not working
Hi,
I worked with Sitefinity 6.1 and json with webMethod but this not working:
Here is the jquery call that is calling the web method:
$.ajax(
type:
"GET"
,
dataType:
"json"
,
contentType:
"application/json; charset=utf-8"
,
url: baseUrl +
"Processes/ItemInfo/GetItemInformation"
,
data: queryString,
success:
function
(data)
alert(
'info'
);
,
error:
function
(response)
if
(response)
setPageLoadErrorMessage(response.toString());
);
);
[WebMethod]
[ScriptMethod(UseHttpGet =
true
)]
public
static
object
GetItemInformation(
decimal
itemNumber,
string
imagePhysicalFileName)
//Get information
return
new
IsValidItem =
false
;
Hello Nathalia,
Thank you for contacting us.
I suggest you use Firebug or Chrome built-in JavaScript debugger in order to see what the issue with this Ajax request is, what the returned errors are.
If ItemInfo is the page which contains the WebMethod, try changing the url to baseUrl + "Processes/ItemInfo.aspx/GetItemInformation".
Please let me know if you find this helpful and if I can assist you any further. Thank you in advance.
Regards,
Vasya Stankova
Telerik
Hi Vasya,
Thanks for replay. I used Firebug and the ajax request not returned errors, the process only not execute the webmethod.
If I use ItemInfo.aspx in the firebug returns a error (attach image) because the page not exist. I don't know if I should use a page.aspx and not page of sitefinity. Can I use pages that I create in Sitefinity for webMethods?
Thanks,
Nathalia.
Hi Nathalia,
Please check out the following few steps:
Hi Vasya,
I creted a file .aspx in sitefinity project and the web methods is working now.
Thanks,
Nathalia
In regards to the baseUrl, what is the correct format?
The path to my SitefinityWebApp project folder could be: "C:\inetpub\WebSite\Public"
And then the rest of the url should be "MyWebForm.aspx/WebMethod"
But how is it supposed to be formatted or how should the final url look?
Thanks in advance
i am also facing same problem, how to call method of service from control (ChangePasswordWidget.ascx)using ajax
1. I have build custom module, and added page widget in that in separate C#library project
2. Added one wcf service in custom modules Web/ Services folder\
3.my ajax function looks like
<script type="text/javascript">
function GetDataService()
$.ajax(
type: "POST",
cache: false,
url: "~/CustomModule.Web.Services/ChangePasswordService",
data: "",
dataType: "text",
success: function (data)
console.log("ajax claaed success");
alert(data);
,
error: function (XMLHttpRequest, textStatus, errorThrown)
alert(textStatus + "," + errorThrown.toString());
);
</script>
Getting below error
localhost:45629/.../ChangePasswordService 405 (Method Not Allowed)
I know issue is with Path but i don not know what path to set to access resources or service function from other custom module build in separate c# library .
Please help me out.
Thanks in advance
Hi
In the ajax call use either absolute or relative Url like:
"/Sitefinity/Services/Content/EventService.svc/"
<%@ ServiceHost
Language=
"C#"
Debug=
"false"
Service=
"Telerik.Sitefinity.Modules.Events.Web.Services.EventService"
Factory=
"Telerik.Sitefinity.Web.Services.WcfHostFactory"
%>
SystemManager.RegisterWebService(
typeof
(MyService),
"/Services/MyService.svc/"
);
Thanks Nikola.
One more issue i am facing is - service from custom module (in separate c# library)is not accessible.
Give below error -
POST localhost:60876/.../ChangePassord 401 (Unauthorized)
How to authenticate service, since i am already logged despite of that giving Unauthorized error.
Hi
Since the service is under /Sitefinity route, it would require backend user authentication. Either move the service to be public one, or authenticate a user that have the rights to call the service. If you want to protect certain service methods, you can use:
ServiceUtility.RequestAuthentication();
ServiceUtility.RequestBackendUserAuthentication();
PageManager manager = PageManager.GetManager();
manager.Provider.SuppressSecurityChecks =
true
;
...
manager.Provider.SuppressSecurityChecks =
false
;
// or better use
using
(
new
ElevatedModeRegion(manager))
...