我試圖參照這個視頻教程: https://www.youtube.com/watch?v=PfnTJsUKxiY 也是這個博客: https://cmsview.wordpress.com/tag/sitecore-speak-for-beginners/獲得404錯誤調用Sitecore的ItemWebApi通過Ajax
他們這些教程的例子都發起Ajax調用的URL /api/sitecore/{controller}/{action}
。它是重定向到該控制器操作的默認Sitecore行爲,還是我需要自行配置路由?正如教程所顯示的,我無法獲得這個網址。每次它是404錯誤。我正在使用Sitecore 8.
謝謝。
編輯:下面 是在我的控制器類的代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace SwireCitygate.Web.Controllers
{
public class MembersBehaviourReportsController : Controller
{
// GET: Default
public ActionResult GetText()
{
string text = "Hello World";
return Json(text, JsonRequestBehavior.AllowGet);
}
}
}
爲繼承System.Web.Mvc.Controller
和JS文件:
define(["sitecore"], function (Sitecore) {
var model = Sitecore.Definitions.Models.ControlModel.extend({
initialize: function (options) {
this._super();
this.set("output", null);
this.GetText(this);
},
GetText: function (app) {
jQuery.ajax({
type: "GET",
dataType: "json",
url: "/api/sitecore/MembersBehaviourReports/GetText",
cache: false,
success: function (data) {
app.set("output", data);
},
error: function() {
console.log("There was an error in GetText() function!");
}
});
}
});
var view = Sitecore.Definitions.Views.ControlView.extend({
initialize: function (options) {
this._super();
this.set("output", null);
}
});
Sitecore.Factories.createComponent("MembersBehaviourReportsDataSource", model, view, ".sc-MembersBehaviourReportsDataSource");
});
你使用的是什麼網址?您不應在他們的網址中使用字詞控制器,例如如果你有'MyCustomController'類,你應該使用'/ api/sitecore/mycustom/someaction'。 –
我正好使用'/ api/sitecore/mycustom/someaction',但它不起作用 – jackielpy
你可以發佈你的代碼嗎? – NikolaiDante