1

In a scope of Sitecore Web project an API Contoller is used. Got the following response error message during jQuery AJAX GET API request:

jQuery AJAX message error

On a back-end side I use IHttpActionResult action method that returns Json object such as return Json(model).

An API Action method looks like below:

public IHttpActionResult Get(Guid id)
{
  var targetItem = Context.Database.GetItem(new ID(id)); var model = new List<T>();

  //business logic where appropriate data<T> (simple properties such as Guid, string) is added to model. 

  return Json(model); 
}

and AJAX call function looks like below:

$.ajax({ 
  type: "GET", 
  url: url, 
  dataType: "json", 
  contentType: "application/json; charset=utf-8", 
  success: function(response) { }, 
  error (req,err){ //here I got "parsererror" message }
}

During this call the following Exception is executed:

Exception: System.InvalidOperationException Message: Attempt to retrieve context object of type 'Sitecore.Mvc.Presentation.PageContext' from empty stack. Source: Sitecore.Mvc at Sitecore.Mvc.Common.ContextService.Peek[T]() at Sitecore.Mvc.Pipelines.MvcPipelineArgs.get_PageContext() at Sitecore.Mvc.ExperienceEditor.Pipelines.Request.RequestEnd.AddPageExtenders.Process(RequestEndArgs args)

This issue is caused on Production CD server. In localhost everything is OK. Any ideas how I can avoid this issue?

8
  • 2
    Welcome to Sitecore Stack Exchange! Can you add some more specifics about the call you're making and your code that receives it? Code snippets will help, too. Jan 10, 2019 at 12:25
  • @DanSinclair Sure, below you can see API Action method: public IHttpActionResult Get(Guid id) { var targetItem = Context.Database.GetItem(new ID(id)); var model = new List<T>(); //business logic where appropriate data<T> (simple properties such as Guid, string) is added to model. return Json(model); } Jan 10, 2019 at 14:52
  • 1
    @DanSinclair and AJAX call function: $.ajax({ type: "GET", url: url, dataType: "json", contentType: "application/json; charset=utf-8", success: function(response) { }, error (req,err){ //here I got parsererror message } Jan 10, 2019 at 14:53
  • just discovered that during this call the following Exception is executed: Exception: System.InvalidOperationException Message: Attempt to retrieve context object of type 'Sitecore.Mvc.Presentation.PageContext' from empty stack. Source: Sitecore.Mvc at Sitecore.Mvc.Common.ContextService.Peek[T]() at Sitecore.Mvc.Pipelines.MvcPipelineArgs.get_PageContext() at Sitecore.Mvc.ExperienceEditor.Pipelines.Request.RequestEnd.AddPageExtenders.Process(RequestEndArgs args) Jan 10, 2019 at 14:58
  • Can you please edit your question to add this information? It will be more useful to potential answerers in the context of your original question. Jan 10, 2019 at 15:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.