Encounter a critical issue while making a JSON request using Kendo UI

I am facing an issue at my workplace where I need to integrate Angular.js with ASP.NET MVC. Currently, I am trying to build a simple application that features a Kendo UI grid on the front page. In my App.js file, I am fetching data from the Data Controller. While the Controller Action is being executed successfully, I encounter an error as soon as the code finishes running:

Below is the relevant portion of my code:

Controller:

[HttpGet]
public JsonResult GetEmergencyRegions([DataSourceRequest]DataSourceRequest request, string searchterm)
{
    var emergencyRegions = _repository.GetEmergencyRegionBySearchTerm(searchterm);
    return Json(emergencyRegions.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

App.js

$scope.gridOptions = {
    columns: [{
        field: "Description",
        title: "Beschreibung"
    }, {
        field: "Region",
        title: "Region"
    }, {
        field: "Phone",
        title: "Telefon"
    }, {
        field: "HasPointOfSale",
        title: "PoS"
    }],
    pageable: true,
    dataSource: {
        pageSize: 5,
        transport: {
            read: function (e) {
                $http.jsonp('/Data/GetEmergencyRegions')
                  .then(function success(response) {
                      e.success(response.data);
                  }, function error(response) {
                      alert('something went wrong')
                      console.log(response);
                  })
            }
        }
    }
};

View with the Grid

<kendo-grid options="gridOptions">

</kendo-grid>

I tried adding ?callback=JSON_CALLBACK to the jsonp URL based on suggestions from Stackoverflow, but it did not resolve the issue.

Notice

Removing JsonRequestBehavior.AllowGet from my Controller eliminates the error, but then I receive a status Code 404.

Answer №1

Looks like you have an extra "," in App.js

Please make the following change:

 columns: [{
    field: "Description",
    title: "Beschreibung"
},

Hope this solution works for you.

Answer №2

Successfully resolved the issue by making the following changes:

  1. Eliminated the DataSourceRequest section in the Controller, which eliminated a critical JavaScript error.

    public JsonResult GetEmergencyRegions(string searchterm)
    {
        var emergencyRegions = _repository.GetEmergencyRegionBySearchTerm(searchterm);
        return Json(emergencyRegions, JsonRequestBehavior.AllowGet);
    }
    
  2. Encountered a 404 error in App.js again. Resolved it by replacing jsonp with get. The solution was found here: AngularJS: how to make a jsonp request

    read: function (e) {
         $http.get('/Data/GetEmergencyRegions?callback=JSON_CALLBACK')
             .then(function success(response) {
                  e.success(response.data);
              }, function error(response) {
                  alert('something went wrong')
                  console.log(response);
         })
    }
    
  3. Implemented the Solution and Celebrate Happiness! :-)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determining the Position of the Cursor Within a Div

When a link is clicked, a pop up is displayed. Here is the code for the pop up: <div class='' id="custom-popover"> <div class="arrow"></div> <h3 class="popover-title">Popover left</h3> <div class="pop ...

Lack of animation on the button

Having trouble with this issue for 48 hours straight. Every time I attempt to click a button in the top bar, there is no animation. The intended behavior is for the width to increase and the left border color to change to green, but that's not what&ap ...

Looking for a jQuery Gantt Chart that includes a Treeview, Zoom functionality, and editing capabilities?

I am in need of integrating a dynamic Gantt Chart tool into a room booking solution using jQuery. The Gantt chart should be highly interactive, allowing for drag-and-drop functionality, a tree view on the left to group tasks, and a zoom feature for adjusti ...

Guidelines for accessing the Coinbase exchange API from a localhost

Following the instructions in the Coinbase Cloud documentation, I tried running this code on the client side using JavaScript: const options = { method: 'GET', headers: { Accept: 'application/json', 'cb-access-key&ap ...

How can you incorporate a custom button into the controlBar on videoJS in responsive mode?

The video player I have created using videoJS includes custom buttons in the control bar. These buttons are not clickable when viewed on mobile or tablet devices without forcing them to work. let myButton = player?.controlBar.addChild('button'); ...

directive still running despite attempting to stop the service

In my modal window, there is a directive that utilizes a service to make HTTP requests at regular intervals using $interval. However, even after closing the modal window, the service continues to run and make requests every 30 seconds. Is there a way to ...

Delay in loading Jquery accordion due to value binding

I've noticed that my jquery accordion takes a significant amount of time to collapse when the page initially loads. After some investigation, I realized that the issue lies in the fact that there are numerous multiselect listboxes within the accordio ...

Transforming the MVC model attribute into an HTML attribute

Is there a way to include model attributes in the HTML input tag? Code [Required] [StringLength(20)] public string Username { get; set; } [Required] [StringLength(20)] [DataType(DataType.Password)] public string Password { get; set; } Expected Output: ...

Developing ES6 modules in C++ using Node.js

Here is a previous example showcasing how to create a Node.js addon in C++: https://nodejs.org/api/addons.html You can use node-gyp to build it into a common JS module, which works well with the 'require' function. However, when trying to impo ...

Validating Web API tokens in AngularJS: A step-by-step guide

Currently, I am focused on AngularJS Authentication and retrieving tokens from a web API. During the route change event, my goal is to validate whether the generated token is valid or not. If it is indeed valid, I aim to redirect to a different route; howe ...

The 'in' operand is invalid

I am encountering a JavaScript error: "[object Object]" TypeError: invalid 'in' operand a whenever I attempt to perform an AJAX request using the following code: .data("ui-autocomplete")._renderItem = function( ul, item ) { return $( " ...

How can communication be established between JavaScript and a .NET app?

I've been developing a help system using HTML, and I want to include clickable links that can trigger commands in a .NET application (such as guiding users through tutorials or workflows). I have explored the TCard() method for HTML help, but it seems ...

Guide to using a JSON WCF service in C#

I have a JSON web service. The address is provided. The WSDL code includes the following: <wsdl:binding name="BasicHttpBinding_iBOER" type="tns:iBOER"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> - <wsdl:operation n ...

The function req.send('null') does not exist in the Node.js MySQL library

I am struggling with inserting a form into a MySql database. The values are stored in the database from the form, but the table displayed on the page does not refresh. I can only see the entries when I restart the server and revisit the page. Furthermore, ...

The primary directory specified in the package.json file

Question: I have a pre-existing library that I want to turn into an NPM module. Currently, the library is being required through the local file system. How can I specify the main directory path for my module's files? If my structure looks like this: ...

In JavaScript, the mousedown event consistently receives the "e" parameter as the event object

I am facing an issue while trying to handle a middle mouse button click event using JQuery on a DataTable from the website https://datatables.net/. Below is the code I have implemented. var tbl = document.getElementById("entries"); $(tbl).on('mousedo ...

Creating Multiple Fieldsets in a Drupal 8 Content Type

I have successfully created a group using a fieldset in the "manage form display" section. However, I am looking to replicate this group multiple times similar to what field collection can do. I prefer not to use field collection as it does not generate JS ...

Troubleshooting the Node.js Server Error Encountered when Enabling AngularJS html5Mode(true)

When using routeProvider and stateProvider in AngularJS with HTML5 mode set to true, everything functions correctly until the page is refreshed. On a Node.js server, I am unsure of what needs to be written on the server side to prevent receiving a "Can no ...

What could be causing the frontend to receive an empty object from the express server?

Struggling to understand how to execute this request and response interaction using JavaScript's fetch() along with an Express server. Here is the code for the server: var express = require('express'), stripeConnect = require('./r ...

Locate and filter elements by using the react-testing-library's getAll method

On my page, I have a collection of unique checkbox elements that are custom-designed. Each individual checkbox has the following structure: <div className="checkbox" role="checkbox" onClick={onClick} onKeyPress={onKeyPress} aria-checked={getS ...