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:

https://i.sstatic.net/7CJnc.png

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

Is there a way to generate and transmit a text file using XmlHttpRequest or $.ajax?

The server is anticipating an html or txt file to be sent from a form named "websitetopdf". The file is dynamically created on client javascript and should only function properly on Chrome. Below is the form that needs to be used for sending: <form ac ...

Adjusting a polyline in Google Maps

I've successfully used Google Maps V3 API to create a polyline with 2 points. However, I now need to shorten the polyline. Issue: My goal is to make the polyline extend from the start point to the midpoint between the start and end points. How can I ...

How can I utilize a filter or pipe to populate product categories onto screens within Ionic 2?

I am considering creating an Ionic 2 app with 6 pages, but I'm unsure whether to utilize a Pipe or a Filter for the individual category pages and how to implement the necessary code. Each category page should be able to display products from the "app ...

Tap on the option labeled 'Google' within the Google Maps application

I recently added Google Maps to my AngularJS mobile project, but I am encountering an issue where a "Google" tag appears in the bottom left corner of my map. When clicked, it redirects me to the Google Maps app and prevents me from returning to my own ap ...

Dropdown feature in the side navigation bar

Is it possible to create a drop-down section in a navigation bar using HTML/CSS/JS? For example, clicking on 'products' would reveal a list of products that disappears when clicked again. If this is achievable, how can it be done? I am currently ...

Using three.js to add an image onto an already existing object

I attempted to modify the appearance of an object by adding an image, but all my tests resulted in a white object... The goal is simply to apply an image to the entire object. Here is my test code: var obj = scene.getObjectByName('wall_20_118') ...

Storing transformed values in a React Functional Component: Best Practices and Considerations

Imagine having a complex calculation function like this: function heavyCalculator(str:string):string{ //Performing heavy calculations here return result; } function SomeComponent({prop1,prop2,prop3,prop4}:Props){ useEffect(()=>{ const result ...

Extracting the name of the file from the image's web address

I have created a simple Chrome extension for personal use and sharing with friends. I am dealing with URLs that have various formats, such as: i.imgur.com/abcd123.png or imgur.com/a2b3c78 or even i.imgur.com/herp321.png?1 All I need from these URLs are t ...

Issue with onblur and focus while returning back from external window

Instructions to reproduce the issue: Important: Set up two input fields with names and add a console.log("Test Focus In" + element.getAttribute("name")) and console.log("Test Blur" + element.getAttribute("name")) statement in the focusin and blur event f ...

Is there a way to determine if an element has been scrolled past?

I am currently working on a script to detect when a specific element comes into view while scrolling. const targetElement = document.getElementById('sidebar'); window.addEventListener('scroll', () => { if (window.scrollY > tar ...

Using jQuery to access the value of the CSS property "margin-left"

I created a JavaScript game with moving divs that have different transition times. The game includes a function that is called every 1/100 seconds, which checks the position of the divs using: $("class1").css("margin-left") Here's the strange part: ...

Send formcollection to action without submitting the form

Is there a way to pass formcollection data to FileContentPath actions that return generated pdf/excel files in the controller? The problem is that the formcollection may change depending on the user's interactions with the page. For example, I have l ...

Performing double string splitting with multiple separators in javascript

If I have a string like a.b.c.d#.e.f.g.h#.i.j.k.l and want to split it first by "#" and then by ".": str = a.b.c.d#.e.f.g.h#.i.j.k.l res = str.split("#") res[0] will contain a.b.c.d after the first split. Now, I need to further split this data. Is th ...

Having issues with Angular jasmine 2 $q promise failing to trigger .then function

Confusion has overtaken me as I try to make sense of the situation at hand and find a solution. My focus is on testing this particular code snippet, but for some reason, .then never seems to get called: describe('PicturesSvc.updatePicturesList', ...

In the template, I utilize both vue-router and jQuery. However, there seems to be an issue with $(document).ready() not functioning

Looking for guidance on using jQuery in Vue. I've noticed that when I refresh the page, $(document).ready() function is triggered. However, when I use vue-router to switch pages, $(document).ready() does not seem to work. <template> <div ...

How can I create a new PHP table using data from an existing table?

I have a table displayed on my website with the code snippet providedview the table image here Here is the code for generating this table: <?php $query = $db->query("SELECT * FROM bit_exchanges ORDER BY id DESC LIMIT 20"); if($query-> ...

Fulfill the promise within the $stateProvider and proceed with utilizing the outcomes

I am facing an issue where I need to resolve a promise in a state provider so that I can use the results of the promise in another promise. I am a bit unsure about how to go about this. I tried the following approach: app .config(['$stateProvid ...

In my coding project using Angular and Typescript, I am currently faced with the task of searching for a particular value within

I am facing an issue where I need to locate a value within an array of arrays, but the .find method is returning undefined. import { Component, OnInit } from '@angular/core'; import * as XLSX from 'xlsx'; import { ExcelSheetsService } f ...

Javascript variable unable to retrieve value from textbox

Hey there! I am having some trouble reading a textbox that is populated from the server into a JavaScript variable. When I try to access it, I get a console error saying "can't read from NULL". However, the text box is definitely populated with the st ...

Babel had a SyntaxError in test.jsx file at line 3, position 11 with an Unexpected token

Having trouble converting JSX to JS with Babel? If you're seeing an error like the one below, don't worry - we can help you fix it: The example code in test.jsx is causing a SyntaxError when transformed using babel test.jsx: SyntaxError: test ...