The alert function in the Ajax web method is malfunctioning

Every time I try to call the Ajax web method, I keep receiving a 'save error' message. However, the data is successfully saved to the database without any issues. I have checked for errors but couldn't find any. How can I display an alert saying 'Saved' after the operation?

$.ajax({
            type: "POST",
            dataType: "json",
            contentType: "application/json",
            url: "paygrade.aspx/SavePayGrade",
            data: JSON.stringify({ value: rec, arr: arr }),
            success: function (msg) {
                console.log(msg.d);
                alert(msg.d);

            },
            error: function (msg) {
                alert("Save error");
            }
        });



 [WebMethod]
  public static string SavePayGrade(string value, params string[] arr)
    {
        string res = "";
        using (FlairEntities context = new FlairEntities())
        {

            tblPayGrade obj = new tblPayGrade();

                obj.salaryGrade = arr[0];
                obj.salary = arr[1];
                obj.note = arr[2];

                context.tblPayGrades.Add(obj);
                context.SaveChanges();
                res = "Saved";

        }

        return res;
    }

Answer №1

Experiment with the following:

console.log(data);

alert(data);

When you are sending a response as a string (return result;), you should not use data.response. Instead, only use data.

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

Exploring the world of jQuery and Ajax: Experimenting with implementing a POST method through Ajax and retrieving the response in HTML

Hey guys, I'm currently attempting to set up a basic HTML post method using Ajax. Take a look at the code snippet below: <?PHP function fetchInstagramData($url) { $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL => ...

Is there a way to access just the concealed text within an element?

Is there a way to create a JavaScript function that can specifically extract hidden text from an element? Are there any existing libraries with this capability, and if so, how efficient are they? In order for an element to be considered visible ac ...

The Webstorm AngularJS extension appears to be malfunctioning, as it is not able to recognize the keyword 'angular'

As a beginner in Angularjs and web development, I have been using Webstorm to develop my projects. I have already installed the Angularjs plugin, which seems to be working fine in my HTML files. However, I am facing an issue with my .js file. In this file, ...

Issue encountered while retrieving values from JSON for the data table

I recently developed an application using a combination of React and Flask to display JSON data in a table format. While I can successfully see the data loaded in the console, I encountered difficulties in rendering it within the data table. The technologi ...

Creating a robust Anti-bot Captcha system in Java Spring MVC, incorporating Thymeleaf and JQuery AJAX for enhanced security

Currently, I am in the process of incorporating Captcha into my Spring MVC application. While I have come across some examples on how to achieve this, none of them demonstrate submitting the form with JQuery AJAX and using Thymeleaf as the template engine. ...

I need to link the click function to the li components within the xpages autocomplete feature

I've successfully implemented Tim Tripcony's advanced type-ahead solution and it's working well. However, I'd like to customize it a bit by redirecting the user to the selected document instead of filling the editbox with the selected d ...

Perform the action: insert a new item into an array belonging to a model

Here is the structure of my model: var userSchema = new mongoose.Schema( { userName: {type: String, required: true}, firstName: {type: String}, lastName: {type: String}, password: {type: String, required: true}, ...

Strategies for loading content lazily on JQuery tabs that is unrelated to the main tab content, such as login or registration sections

I am utilizing lazy loading to display 3 tabs in an ASP.NET MVC web application using Query tabs. However, I also have a Login section (username and password) that I want to be displayed in the tab content area when the user clicks on a link at the top o ...

How to choose the second anchor element in a list with Protractor

I am facing a challenge where I need to click on the 2nd anchor tag in a list of anchor tags. <ul id="shortcuts"> <li><a ui-sref="app.journeyExplorer" href="#/journey-explorer/"><span class="ng-binding">1</span></a> ...

Angular.js dynamically changing ng-class based on long-polling updates to a monitored variable

Currently utilizing angular.js for my project. I am implementing long polling with a server and would like to dynamically update an element in the view, specifically one with a class of 'updated', whenever the value of build_tag is incremented. ...

Assistance needed with extracting specific information using Ajax and C#

I have developed an employee management website using .Net and ASP Entity Framework. On the main page, you can view a list of all employees with their names. However, clicking on a specific employee takes you to another page Profile/Index, where only deta ...

Prevent the use of unnecessary object properties

Currently, my project involves using Typescript and React in conjunction with Material-UI. Specifically, I am utilizing Material-UI's styling solution, which implements CSS in JS methodology in a Hook-like manner as outlined in their documentation: co ...

The JSON data unexpectedly encountered a non-whitespace character at line 1, column 50 during JSON parsing

Whenever I attempt to use the following code: var jsonData = JSON.parse(xhttp.responseText); An error is thrown, stating: "JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 50 of the JSON data" The JSON data in question i ...

I have encountered a node.js error related to the 'Require Stack'

Encountering an error in my node.js application when trying to open a .js file { code: 'MODULE_NOT_FOUND', requireStack: } Unable to determine the root cause of this issue I have tried re-installing Node.js and its packages, removed and added b ...

Troubleshooting Routing Issues in a Next.js Website Tutorial

After going through the next.js tutorial at https://github.com/zeit/next-learn-demo.git, I encountered an issue starting from stage 3 "dynamic routing". Despite the tutorial indicating that dynamic routing should be working from stages 3 to 8, it wasn&apos ...

Fixed position scrollable tabs with Material UI

I recently implemented material-ui scrollable tabs in my project, referencing the documentation at https://mui.com/material-ui/react-tabs/#scrollable-tabs. Here is a snippet of the code I used: <Tabs value={value} onChange={handleChange ...

Is there a way to implement an event listener for a customized select element within a table on a webpage?

I have a table that contains columns populated from a database. I also have a custom select dropdown in one of the columns, along with an update button. I want to create an event listener for the button that captures the user's selection from the cust ...

Error: The JavaScript SRC cheat is malfunctioning

Having an issue with the code below. The 'dummy1' and 'dummy2' variables are not loading their content as expected on the page. Any suggestions? <html> <head> <title>JavaScript On-line Test</title> <script LA ...

When a model is changed from within a jQuery event, Angular 2 fails to update the view

During the development process, I encountered an issue while creating a custom search panel that displayed search results in a dropdown container. In my controller, I defined the following: export class ProductSearchComponent implements OnInit { publ ...

Attempted to fetch information using Ajax in Grails

I am attempting to utilize jQuery and ajax with the Grails framework to load the content registration page. However, upon loading the page, I am encountering an issue where the menu and registration fields are duplicated within the page. <script src ...