Display the feedback within the div container

I am using AJAX to call a method and I'm receiving a response successfully. However, I am struggling to display that response in a div. I want the response to be shown in a #result div element.

<div id="result"></div>
<input type="button" name="name" value="try" onclick="DepListQuery()" />

<script>
    function DepListQuery() {
        $.ajax({
            type: 'GET',
            url: '@Url.Action("GetData","Home")',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {

                alert(response);
            },
            failure: function (response) {
                alert("something went wrong u.u");
            }
        });
    }
</script>

Below is the code for my method:

[HttpGet]
public ActionResult GetData()
{   
    var st = "kyo please help me u.u";
    return Content(st);
}

Answer №1

To start, make sure to update your GetData method so that it returns Json:

[HttpGet]
public ActionResult GetData()
{
    var message = "Please help me with this issue.";
    return Json(new { success = true, message }, JsonRequestBehavior.AllowGet);
}

Afterwards, you can display the response in your div element using the following code:

success: function (response) {
    $('#result').text(response.message);
},

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

An issue occurred while trying to process the XHR response text for files of a large size

I've been using the Jquery fineUploader to upload files and I've encountered the following error message: 404 - File or directory not found. This error occurs when trying to upload files larger than 30MB, while smaller files below 30MB upload w ...

Activate a CSS class on click using JavaScript

Having a bit of trouble as a beginner with this. Any help would be much appreciated. This is the code in question: HTML: <div class='zone11'> <div class='book11'> <div class='cover11'></d ...

Building a dynamic Single Page Application with the power of Durandal

Our vision for the single-page app is to create a dynamic system where users can personalize their views and widgets in real-time. Instead of predefined views and viewmodels on the server, we want end-users to have the flexibility to define and customize w ...

Troubleshooting issues with Angular 2 HTTP post and Web API integration

Here is an example of my Web Api Core Controller Method: public void Post(Sample sample) { _sampleService.CreateSample(sample); } The Sample POCO is defined as follows: public class Sample : BaseEntity { public string BarCode { get; s ...

Does adding .catch resolve a promise?

Being new to typescript / javascript, I have limited knowledge about promises. My current scenario involves creating three distinct promises within a cloud-function and subsequently returning them using Promise.all([promise1, promise2, promise3]). Each of ...

What is the method to determine the index of a removed element within a subarray?

In my array, all = [2,3,4,12, 55,33], there is a sub-array named ar1 = [12, 55, 33] starting from the value 12. If I remove a value from all that is present in ar1 (e.g. 12), how can I determine the index of this value in ar1 (0 for 12) so I can also remo ...

*Difficulty in locating particular item on the webpage

While I have come across similar questions on this topic, none of them seem to address my specific issue: I am working with a lightbox that contains multiple elements. Interestingly, I can locate and interact with all these elements using XPath except for ...

Determining the minimum and maximum values within an array

Currently, I am making modifications to a program created by an unknown individual, possibly a teacher. The program is designed to showcase stock values stored in an array through a graph. The teacher has pointed out an issue with the Y-axis on the graph, ...

Utilizing 'this' in jQuery: Image swapping with thumbnails, Twitter Bootstrap framework

Is it possible for jQuery's 'this' to simplify my code? You can view the full code here. Thank you for any help or suggestions. Here is the jQuery code: /* Ref: http://api.jquery.com/hover/ Calling $( selector ).hover( handlerIn, handler ...

When attempting to utilize the Vuex store in a child component, it appears to be ineffectual

I'm experiencing an issue with the vuex-Store. There is a state in my store that is not being updated when the Action is called. Can anyone help me out here? The problem lies with the "selectedHive" state. The axios call is functioning properly and ge ...

Assistance with utilizing Google Sheets scripts for retrieving formulas is needed

I've been working on a small search tool in Google Sheets as a personal project to improve my skills and knowledge of GS. Munkey has been guiding me over the past few weeks and helping me develop my understanding. Below are the links to my "Database" ...

Sequelize: When attempting to use .get({plain: true})) method, an error is returned indicating that .get is

I'm facing a strange issue as I am able to retrieve only the values of an instance in other parts of my code without any problems. Can you spot what might be wrong with my current code? app.get('/profile', checkAuth, function(req, res) { ...

For optimal display on mobile devices, include "width=device-width" in the meta tag "viewport"

Is it necessary to include "width=device-width" in the meta tag named viewport when dealing with mobile phones? I've been attempting to make use of this, but without success: //iPhone Fix jQuery(document).ready(function(){ if (jQuery(window).widt ...

Looking to update this jQuery pop-up menu script to be compatible with Ajax functionality

I came across this script at The issue arises when the script is called multiple times, resulting in a cascade of pop-outs within pop-outs. I am currently exploring ways to prevent the execution of the script if the pop-out has already been set. Below is ...

Steps to Start VStudio 2015 RC for ASP.NET vNext

I downloaded VSStudio 2015 from this website: http://www.asp.net/vnext After a successful installation, I couldn't find the icon on my desktop to run the program. Can anyone help me understand why this is happening? ...

Incorporating a for loop, ExpressJS and Mongoose repeatedly utilize the create method to generate

When users input tags separated by commas on my website, ExpressJS is supposed to search for those tags and create objects if they don't already exist. Currently, I am using a for loop to iterate through an array of tags, but only one object is being ...

Tips for implementing custom fonts in NextJS without relying on external services

Utilizing Fonts in NextJS I have been researching various methods for using self-hosted fonts with NextJS. When attempting the following code, I encountered a [ wait ] compiling ...: @font-face { font-family: 'montserrat'; src: url(&a ...

Is there a Discrepancy in Values Returned When Invoking a C Function from C# Using P/Invoke on Different Platforms (X86 vs. X64)?

I hate to admit it, but I've been stuck on this problem for hours now and I just can't seem to figure out what's wrong. In a C DLL, I have the following function signature: __declspec(dllexport) _Bool __cdecl cs_support(int query); To cal ...

Convert the date and time of "2018-03-31T05:37:57.000Z" to a

I need help converting the universal time 2018-03-31T05:37:57.000Z to a timestamp in the form of 1520919620673. Can someone please provide guidance on how I can achieve this conversion? ...

Utilize Entity Framework 5 to efficiently load related entities with filtering through the Include method

So I have two tables at my disposal Candidates Id Name 1 Tejas 2 Mackroy Experiences Id Designation CandidateId isDeleted 1 Engineer 1 true 2 Developer 1 false 3 Tester ...