Javascript Dotnetnuke从模块调用ajax
我现在尝试使用ajax调用构建dnn模块。但是有一个jquery错误声明Javascript Dotnetnuke从模块调用ajax,javascript,jquery,ajax,dotnetnuke,dotnetnuke-7,Javascript,Jquery,Ajax,Dotnetnuke,Dotnetnuke 7,我现在尝试使用ajax调用构建dnn模块。但是有一个jquery错误声明 SyntaxError:意外标记您遇到的问题是DNN没有正确处理您正在调用的请求URL。如果要在DNN中调用服务URL,则需要设置路由来处理调用 namespace Christoc.Com.Modules.SlidePresentation.services { public class SlidePresentationRouteMapper : IServiceRouteMapper {
SyntaxError:意外标记您遇到的问题是DNN没有正确处理您正在调用的请求URL。如果要在DNN中调用服务URL,则需要设置路由来处理调用
namespace Christoc.Com.Modules.SlidePresentation.services
{
public class SlidePresentationRouteMapper : IServiceRouteMapper
{
public void RegisterRoutes(IMapRoute mapRouteManager)
{
mapRouteManager.MapRoute("SlidePresentation", "{controller}.ashx/{action}",
new[] {"Christoc.Com.Modules.SlidePresentation.services"});
}
}
}
在控制器中,可以定义可用的方法
[DnnAuthorize(AllowAnonymous = true)]
public ActionResult ListOfSlides()
{
try
{
var slides = Slide.GetSlides(ActiveModule.TabID, ActiveModule.ModuleID);
return Json(slides, JsonRequestBehavior.AllowGet);
}
catch (Exception exc)
{
DnnLog.Error(exc);
return Json(null, JsonRequestBehavior.AllowGet);
}
}
示例Javascript
//get slides on initialization
this.init = function(element) {
//var data = {}; //removed because we don't need this
//data.moduleId = moduleId; //removed because we don't need this when calling setModuleHeaders
//data.tabId = tabId; //removed because we don't need this
//serviceFramework.getAntiForgeryProperty(); //removed because we don't need this
$.ajax({
type: "POST",
cache: false,
url: baseServicePath + 'ListOfSlides',
//data: data,
//dataType:"json",
beforeSend: serviceFramework.setModuleHeaders
}).done(function(data) {
viewModel.slides = ko.utils.arrayMap(data, function(s) {
return new slide(s);
});
ko.applyBindings(viewModel);
$(element).jmpress();
}).fail(function () {
Console.Log('Sorry failed to load Slides');
});
};
下面是一个示例模块,可以实现这一点
几年前我在这个模块上做了一个用户组视频。
谢谢。我现在明白了。:)