This is a migrated thread and some comments may be shown as answers.

Error! The requested URL did not return JSON.

26 Answers 701 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stéphan Parrot
Top achievements
Rank 1
Stéphan Parrot asked on 04 May 2010, 03:13 PM
I have a very frustrating problem but tried all solutions I could find on the net, telerik's forum, blog posts but to no avail...
It only happens in IE 8... In Firefox, it's all working 100%
When using the Grid in Ajax mode (Ajax binding), in IE8, I get

Error! The requested URL did not return JSON.

I have tried to set the getters of my complex type objects in my Entity Model (I use EF4) to Internal as suggested here, I also traced the javascript code to find out that on line 5196 of jQuery.1.4.2.js that the data content is set to "" but should contain the JSON returned in my controller like this:

 
        [GridAction]  
        public ActionResult _Index(string productCode)  
        {  
             ViewData["productCode"] = productCode;  
             return View(new GridModel(_productManager.GetProductList(productCode));  
        } 

My grid is set up like this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<SimpleProductDto>>" %>  
<%  
    Html.Telerik().Grid(Model)  
        .Name("products")  
        .DataKeys(keys =>  
            keys.Add(o => o.ID).RouteKey("id")  
        )  
        .DataBinding(dataBinding =>  
        {  
            dataBinding.Server().Select("Index""Product"new { productCode = (string)ViewData["productCode"] ?? string.Empty });  
            dataBinding.Ajax().Select("_Index""Product"new { productCode = (string)ViewData["productCode"] ?? string.Empty });  
        })  
        .Columns(columns =>  
        {  
            columns.Bound(o => o.ID;  
            columns.Bound(o => o.Name);  
            columns.Bound(o => o.Description);  
        })  
            .Pageable((paging) =>  
                paging.Enabled(true)                  
                .PageSize(15)  
                .Style(GridPagerStyles.Status |  GridPagerStyles.NextPreviousAndNumeric)  
                .Position(GridPagerPosition.Both))                  
            .Render();  
           
                                                          
%>  
 

I'm really stumped on this one...

Thanks a lot!

Stéphan

26 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 04 May 2010, 03:58 PM
Hello Stéphan Parrot,

What happens if you step in your action method with the debugger? This error is shown if the action method does not return JSON but regular HTML. This can occur in case of missing [GridAction] attribute or unhandled exception.

Kind regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Stéphan Parrot
Top achievements
Rank 1
answered on 04 May 2010, 04:41 PM
In the code snippet I sent in my previous post, The GridAction attribute is there. I've traced my code and the data is returned fine and besides, everything works in Firefox.
For now, I just commented out the ajax databinding in the grid configuration but, it's not a viable option for mid to long term project's quality requirements.
We cannot also force our users to only use firefox.
I'm sure there's an explanation to this behavior but, I can't pinpoint it at the moment.
0
Atanas Korchev
Telerik team
answered on 04 May 2010, 04:42 PM
Hi Stéphan Parrot,

Unfortunately this is not a known issue. Our online demos that utilize ajax binding work in every supported browser. Is there any chance for you to send us a sample project? To do so you can open a support ticket.

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Stéphan Parrot
Top achievements
Rank 1
answered on 04 May 2010, 04:45 PM
Hmmmm I can try to reproduce the problem in a small project but this will require me some time...
Let me check that out and I will open up a ticket ultimately.

Thanks,

Stéphan
0
Stéphan Parrot
Top achievements
Rank 1
answered on 04 May 2010, 09:37 PM
Wow!
I've figured out that, I had to add a small jquery fix for getting the XMLRequestHttp header in the request on specific events related to MVC and action filters which were conflicting with jQuery's ajax support... This was preventing the proper functioning of ajax calls within the grid...
I've removed the offending code and now, everything works except my filter but, I will get around this another way!

Thanks for trying to help me out! :)
0
Muhammad
Top achievements
Rank 1
answered on 09 Sep 2010, 02:58 PM
I'm having the same issue. Can you suggest what exactly was the conflict with jquery and how to remove it?
0
Jay
Top achievements
Rank 1
answered on 17 Sep 2010, 03:19 AM

I get the same error when sending back an empty set of data to the grid.  When there is at least one row, things work fine.  Is there a way to handle this?
0
Stéphan Parrot
Top achievements
Rank 1
answered on 17 Sep 2010, 03:15 PM
Hi Muhammad,
Sorry about the delay, I'm very busy!
Sadly, I haven't posted any replies in this thread about my deception about not being able to fix the issue... 
The "fix" I've found out broke something else and in the end, we dropped the ajax usage for the grid and sticked to server binding.
Later on, we will try to get it working with ajax if possible at all but for now, we cannot afford to waste anymore time on kick-knacks such as these...
Sorry i can't come up with a better answer than this one...

Good luck and feel free to share your findings in here if you manage to fix the problem!

Stéphan
0
El Roy
Top achievements
Rank 1
answered on 19 Oct 2010, 04:28 AM
I also encounter this problem.  I can easily reproduce this problem if I interrupt the page with grid that has 
ajax binding and  client rowdatabound event that also do ajax request.

0
El Roy
Top achievements
Rank 1
answered on 19 Oct 2010, 05:06 AM
And now I can reproduce this more easily using the telerik demo page

Step
1. Visit http://demos.telerik.com/aspnet-mvc/grid/ajaxbinding
2. Visit http://demos.telerik.com/aspnet-mvc/grid/grouping
3. Hit Forward button 
4. Hit back button
5. Repeat 3-4 repeatedly.  Make sure you hit back/forward while grid is loading. :)


0
Ryan
Top achievements
Rank 1
answered on 26 Oct 2010, 01:43 PM
I was just about to post this bug.

We also encounter it when the users clicks through to another page whilst the ajax request is still processing.  Which is exactly what the last poster has described.

As a workaround you can just disable the error message in telerik.grid.js:

success: $.proxy(function(data, status, xhr) {
    try {
        data = eval('(' + data + ')');
    } catch (e) {
        // in case the result is not JSON raise the 'error' event
        //if (!$t.ajaxError(this.element, 'error', xhr, 'parseeror'))
        //    alert('Error! The requested URL did not return JSON.');
        return;
    }


It's up to you if you consider this error worse than the alternative (hiding actual faults).
0
CD
Top achievements
Rank 1
answered on 30 Sep 2011, 04:15 PM
I am getting this error in my app constantly. When I switch pages or content it just dies on this error and I have to refresh back to the home page to get it to start working and then it randomly dies. Once it happens the site is broken until it is refreshed. HELP!!
I'm using version 9.14 of the mvc extensions
0
Atanas Korchev
Telerik team
answered on 03 Oct 2011, 10:42 AM
Hi Cd,

 The OnError event is raised when there is unhandled server-side exception or the action method which binds the grid does not return JSON. The latter may happen in case of session timeout. We can't tell if this happens in your case based on the post. You can use a sniffer tool (Fiddler, FireBug etc) to see what the actual server response is when the OnError event is raised. Then based on that info you can act accordingly.

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
CD
Top achievements
Rank 1
answered on 03 Oct 2011, 01:08 PM
Ok, I can't see how it's an error in the action because the actions all work just fine and then boom! I get the error and then none of the actions work. So if it's a timeout, how do I keep the site/page/data from timing out? I want the pages to stay alive until the page is closed
0
Atanas Korchev
Telerik team
answered on 03 Oct 2011, 01:22 PM
Hi Cd,

We are not sure whether you are experiencing a session timeout or some other problem. Thus we cannot give any specific instructions about resolving it.

A good starting point would be to log somehow what the server response is when the OnError event is raised. There are two options to do so:
  1. Use a traffic sniffer tool such as Fiddler or Firebug. You would be able to see the whole server response.
  2. Use the OnError event itself to print the server response:

function Grid_onError(e) {
     //the current XMLHttpRequest object
    var xhr = e.XMLHttpRequest;
    // get the raw server response and alert it
    alert(xhr.responseText);
}


Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
dipakdave1983
Top achievements
Rank 1
answered on 03 Nov 2011, 12:07 PM
I think the problem occurs when into _AjaxBinding()  method, your context object has foreign key references and so it includes that object reference it has problem.
0
Lucious
Top achievements
Rank 1
answered on 26 Jan 2012, 06:38 AM
Hi Ladies, i struggled with this for a very long time now, but the good news is "I'v managed to trace my problem".
The error pops when you try to populate your grid with an empty model/View/Table or what ever you may be using to populate the grid.

My solution was to check first whether the model is empty or not before i populate it to my grid.

@if(Model.tableName.Count() > 0)
{

put your grid code here

}

Hope someone will learn something from this one.
Luv South Africa.
0
Prasanna
Top achievements
Rank 1
answered on 28 Feb 2012, 11:11 AM
Hi,

I am using custom binding with MVC Telerik Grid.
I am trying to use sorting as well as Paging but in this case as per follwing URL,I modified my code.
http://demos.telerik.com/aspnet-mvc/razor/grid/customserverbinding 

While sorting and Paging I am getting this error "Error! The requested URL did not return JSON."

I am stucked in this issue.
Please help me out.






0
Dadv
Top achievements
Rank 1
answered on 28 Feb 2012, 02:50 PM
Calm :)

Give us some copy/past of your view and controller please.
0
Prasanna
Top achievements
Rank 1
answered on 29 Feb 2012, 07:48 AM
View 

     @(Html.Telerik().Grid(Model)
        .Name("MediaCostConfig")
        .EnableCustomBinding(true)
        .HtmlAttributes(new { id = "Grid_wrapper" })
        .DataKeys(keys => keys.Add(d => d.MediaCostConfigID))
            
        .DataBinding(dataBinding => dataBinding
            .Ajax().Update("Edit", "DisplayCostConfig"))


        .Columns(columns =>
                {
                    columns.Bound(d => d.MediaCostConfigID)
                    .Template(
                    @<text>
        <input type='checkbox' id='chkMessage' name='checkedMovies' value='<#= MediaCostConfigID #>' />
        </text>)
                    .ClientTemplate("<input type='checkbox name='checkedRecords' value='<#= MediaCostConfigID #>' />")
                    .Title("")
                    .Width(36)
                    .HtmlAttributes(new { style = "text-align:center" });
                    columns.Command(commands =>
                    {
                        commands.Edit().ButtonType(GridButtonType.Image);
                    }).Width(50);
                    columns.Bound(d => d.MediaCostConfigID).Width(0);
                    columns.Bound(d => d.SiteName).Width(100);
                    columns.Bound(d => d.PlacementName).Width(200);
                    columns.Bound(d => d.Placement);
                    columns.Bound(d => d.StartDate);
                    columns.Bound(d => d.EndDate);
                    columns.Bound(d => d.Units);
                    columns.Bound(d => d.Rate);
                    columns.Bound(d => d.Agency);
                    columns.Bound(d => d.Serving);
                    columns.Bound(d => d.CostStructureID).Width(0);
                    columns.Bound(d => d.CostStructure);
                })
        .Editable(editing => editing.Mode(GridEditMode.PopUp))
        .ClientEvents(events => events.OnEdit("onEdit"))


                 .Pageable(paging => paging.Total(20))
                   //.Pageable(settings => settings.Total(20))
        .Filterable()
        .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn))        
        .Scrollable(scrolling => scrolling.Height(500))
)


Controller

public class DisplayCostConfigController : Controller
    {
      
        DCCManager dm = new DCCManager();
        DateTime startDate = Convert.ToDateTime("01/01/2011");
        DateTime endDate = Convert.ToDateTime("01/01/2012");


        public ActionResult Index()
        {
            return View();
        }


        [HttpGet]
        public ActionResult DCCHome()
        {
            GridCommand command = new GridCommand();
            return View(dm.DCCSelectAll(startDate, endDate, command.Page, command.PageSize));
        }


        [HttpPost]
        [GridAction(EnableCustomBinding=true)]
        public ActionResult DCCHome(FormCollection collection,GridCommand command)
        {
  var data = dm.DCCSelectAll(startDate, endDate, command.Page, command.PageSize);
            if (command != null)
            {
                var total = data.Count();
                ViewData["Total"] = total;


                data = ApplyPaging(command.Page, 10, data);
                if (command.SortDescriptors != null)
                {
                    command.SortDescriptors.Add(new SortDescriptor());


                    data = AdminHelper.ApplySorting(data, command.GroupDescriptors, command.SortDescriptors);
                }
            }
   return View(data);
        }

  private IList<DCCResult> ApplyPaging(int currentPage, int pageSize, IList<DCCResult> data)
        {
            if (pageSize > 0)
            {
                data = data.Skip((currentPage - 1) * pageSize).ToList();
            }


            data = data.Take(pageSize).ToList();
            return data;
        }


0
Dadv
Top achievements
Rank 1
answered on 29 Feb 2012, 10:05 AM
hi,

it was a little disconcerting, you don't have any ajax Select, and no "Edit" method in your controller.
try something like this (from the telerik example http://demos.telerik.com/aspnet-mvc/grid/custombinding and http://demos.telerik.com/aspnet-mvc/grid/editingajax ) : 



@(Html.Telerik().Grid<YourModel>()
        .Name("MediaCostConfig")
        .EnableCustomBinding(true)
        .HtmlAttributes(new { id = "Grid_wrapper" })
        .DataKeys(keys => keys.Add(d => d.MediaCostConfigID))
             
        .DataBinding(dataBinding => dataBinding
            .Ajax().Update("Edit", "DisplayCostConfig")//Didn't exist in controller
.Select("DCCHome_Select","DisplayCostConfig")
)
 
 
        .Columns(columns =>
                {
                    columns.Bound(d => d.MediaCostConfigID)
                    .Template(
                    @<text>
        <input type='checkbox' id='chkMessage' name='checkedMovies' value='<#= MediaCostConfigID #>' />
        </text>)
                    .ClientTemplate("<input type='checkbox name='checkedRecords' value='<#= MediaCostConfigID #>' />")
                    .Title("")
                    .Width(36)
                    .HtmlAttributes(new { style = "text-align:center" });
                    columns.Command(commands =>
                    {
                        commands.Edit().ButtonType(GridButtonType.Image);
                    }).Width(50);
                    columns.Bound(d => d.MediaCostConfigID).Width(0);
                    columns.Bound(d => d.SiteName).Width(100);
                    columns.Bound(d => d.PlacementName).Width(200);
                    columns.Bound(d => d.Placement);
                    columns.Bound(d => d.StartDate);
                    columns.Bound(d => d.EndDate);
                    columns.Bound(d => d.Units);
                    columns.Bound(d => d.Rate);
                    columns.Bound(d => d.Agency);
                    columns.Bound(d => d.Serving);
                    columns.Bound(d => d.CostStructureID).Width(0);
                    columns.Bound(d => d.CostStructure);
                })
        .Editable(editing => editing.Mode(GridEditMode.PopUp))
        .ClientEvents(events => events.OnEdit("onEdit"))
 
 
     .Pageable()
        .Filterable()
        .Sortable(sort => sort.SortMode(GridSortMode.MultipleColumn))       
        .Scrollable(scrolling => scrolling.Height(500))
)



public class DisplayCostConfigController : Controller
 {
    
     DCCManager dm = new DCCManager();
     DateTime startDate = Convert.ToDateTime("01/01/2011");
     DateTime endDate = Convert.ToDateTime("01/01/2012");
 
 
     public ActionResult Index()
     {
         return View();
     }
 
 
     [HttpGet]
     public ActionResult DCCHome()
     {
         return View();
     }
 
 
     [GridAction(EnableCustomBinding=true)]
     public ActionResult DCCHome_Select(GridCommand command)
     {
         if (command != null)
         {
             var data = dm.DCCSelectAll(startDate, endDate, command.Page, command.PageSize); //your entities model take page and pagesize in parametter, did it do paging it self? if yes, why paging in controller?
 
             var total = data.Count();
 
 
             data = ApplyPaging(command.Page, 10, data);// pageSize fixed to 10.. but you use the command.PageSize above
 
             if (command.SortDescriptors != null)
             {
                 command.SortDescriptors.Add(new SortDescriptor());
 
 
                 data = AdminHelper.ApplySorting(data, command.GroupDescriptors, command.SortDescriptors);
             }
 
             return View(new GridModel
                         {
                             Data = data,
                             Total = count
                         });
         }
         return View(new GridModel());
     }
 
     private IList<DCCResult> ApplyPaging(int currentPage, int pageSize, IList<DCCResult> data)
     {
         if (pageSize > 0)
         {
             data = data.Skip((currentPage - 1) * pageSize).ToList();
         }
 
 
         data = data.Take(pageSize).ToList(); // what if pageSize == 0 ?
         return data;
     }
 }



I'm sure this will not work well because of the missing part. please give me a sample project to have more information.

Regards,
0
Chillax
Top achievements
Rank 1
answered on 22 May 2012, 08:57 AM
Hi Telerik Masters

I am new to Telerik MVC and stuck from last day at the 

Error! The requested URL did not return JSON.

kindly help ASAP. As i have to deliver the project.

Thank You

0
Dadv
Top achievements
Rank 1
answered on 23 May 2012, 10:09 AM
Hi,

Use the network watcher (F12 on IE and Chrome) to look at the response, often the error will be more readable.
0
Chillax
Top achievements
Rank 1
answered on 29 May 2012, 12:54 PM
Hi

Thanks for response. My problem was solved by an expert's advice. I just threw a GridModel despite of throwing my partial view. Here is the new code that work for me..

return View(new GridModel(myListofElements));
0
Sreyas
Top achievements
Rank 1
answered on 30 May 2012, 09:38 AM
Dear friend,

This warning comes because your controller is not return Json.You are calling a POST in the .chtml file.So the post in the basis of json.
So the better way to avoid this waring is,return as JSON

return Json(new GridModel(_productManager.GetProductList(productCode));

If it still exists,then you can comment the warning in telerik.min.js file



Sreyas MN
0
Chillax
Top achievements
Rank 1
answered on 30 May 2012, 11:23 AM
Hi Sreyas

Thank you for response.....my problem was solved :)
Tags
Grid
Asked by
Stéphan Parrot
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Stéphan Parrot
Top achievements
Rank 1
Muhammad
Top achievements
Rank 1
Jay
Top achievements
Rank 1
El Roy
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
CD
Top achievements
Rank 1
dipakdave1983
Top achievements
Rank 1
Lucious
Top achievements
Rank 1
Prasanna
Top achievements
Rank 1
Dadv
Top achievements
Rank 1
Chillax
Top achievements
Rank 1
Sreyas
Top achievements
Rank 1
Share this question
or