Having trouble with functions in jQuery Ajax calls to ASMX files

I have a form in my web application that submits data through an ajax call to an asmx web service. The insertion of data into the database is successful, however, neither the success nor error function seems to be triggered afterwards. The first alert message pops up as expected, but the following functions do not work. Any suggestions on how to fix this issue?

Here is the jQuery code I am using:

        $("#AddSupplierBtn").click(function()
        {

            alert("This is the initial alert message");
            if ($("#AddSupplier").valid())
            {
                $.ajax({
                    type: "POST",
                    url: "/StockPileDelivery.asmx/TestMethod",
                    data: JSON.stringify({
                        SupplierName: $('#SupplierName').val(),
                        SupplierType: $('#SupplierType').val(),
                        SupplierPremium: $('#SupplierPremium').val(),
                        SupplierLocation: $('#SupplierLocation').val()
                    }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        alert("Response received successfully - " + msg.d);
                    },
                    error: function (xhr,status,error) {
                        var err = eval("(" + xhr.responseText + ")");
                        alert(err.Message);
                    },
                });
            }
        });

Answer №1

By switching the button type from submit to button, I was able to successfully achieve the desired functionality:

<button type="button" class="btn btn-primary" id="AddSupplierBtn" name="AddSupplierBtn">Submit</button>

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

The content of XMLHttpRequest is accessible via the property response

Typically, when we want to retrieve data using AJAX, we would use code like this: var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState == 4 && xhr.status == 200){ elem.innerHTML = xhr.responseText; ...

encountering error 404 with rails and ajax request

I encountered this particular error in my Rails logs: Completed 404 Not Found in 11ms ** [Raven] User excluded error: #<ActionController::RoutingError: Not Found> ActionController::RoutingError (Not Found): app/controllers/schools_controller.rb:6 ...

Using jQuery to eliminate repetitive line dividers in a document

Is there a way to remove duplicate dividers in my bootstrap pull-down menu (MVC5 website) that appear stacked up due to user permissions? Here is an example of the issue: <li class="divider"></li> <li>@Html.RouteLink("option1", "Route1") ...

Updating parameter value upon the execution of an internal function in Javascript

How can I log the text from a textbox to the console when a button is clicked in this code snippet? <body> <input type="text" id="ttb_text" /> <script type="text/javascript"> function AppendButton() { var _text = ''; ...

Reaching out to the Edge: Enhancing the jQuery Slider Experience

Alright, I'm really excited about using this amazing slider. What I love most is the "free mode" feature that creates this stunning sliding effect. The size and number of slides are absolutely perfect for me. But there's just one small adjustment ...

Interactive Show Map with Autocompletion Feature

I attempted to implement autocompletion for my application and integrate it with Google Maps, but I'm encountering issues. The code for autocompletion is located in a separate JavaScript file called autocomplete.js. Since I already have a Google Map ...

Experience the thrill of receiving a triumphant notification upon submission of your form

I'm currently learning about jquery and how to use it with ajax to insert and display data in a mysql table. I've been trying out some code that inserts and displays records from a mysql database. Right now, my goal is to make the success message ...

Ways to expand the border horizontally using CSS animation from the middle

Currently, I am experimenting with CSS animation and I have a query regarding creating a vertical line that automatically grows in length when the page is loaded. I am interested in making the vertical line expand from the center in both upward and downwar ...

How to make Jquery skip over elements with a particular data attribute

I am looking to select all elements that are labeled with the 'tag' class. Once these items have been selected, I would like to remove any items from the list that contain the attribute 'data-tag-cat'. var tags = $('.tag'); c ...

Perform a Node.js GET request following a previous AJAX POST request

Having a major issue with using AJAX... I am not receiving the expected 304 page after a successful AJAX request... here is my code snippet: $.ajax({ url: "/crawling/list", type: "POST", dataType: "json", ca ...

The function WebForm_DoCallback is not recognized

Encountering an error where WebForm_DoCallback is undefined. UPDATE WebForm_DoCallback("AccountPageControl1", "FileSave~" + fileName, CVFileSavedServerResponse, null, null, true); function CVFileSavedServerResponse(param, context) { } Why isn't ...

Chrome full screen mode can be toggled on websites after ajax data has loaded

I am currently experiencing a frustrating issue with Chrome on my webpage. The pagination feature loads content via an ajax call at: Whenever I click on the 2nd, 3rd, or subsequent tab in the pagination, the load process occurs but then suddenly jumps int ...

Discover the ultimate guide to harmonize IE 9 with the ingenious Bootstrap Multiselect plugin developed by davidstutz

I've come across an amazing plug-in developed by David Stutz that allows for a Bootstrap and jQuery multi-select options list. Here are some resources: Check out the source code on Github Find documentation and examples here This plug-in works fla ...

Having issues with jQuery hover effects? Consider looking into these two common problems: 1. Is z-index causing any complications?

Do you think these issues would be better addressed separately, or should they remain together as one topic? The code in question can be found in this fiddle: http://jsfiddle.net/jhacks/xCcdn/89/. I felt it made sense to combine them into one discussion fo ...

Refresh the page and witness the magical transformation as the div's background-image stylish

After browsing the internet, I came across a JavaScript script that claims to change the background-image of a div every time the page refreshes. Surprisingly, it's not functioning as expected. If anyone can provide assistance, I would greatly appreci ...

How to handle a bad request response in AJAX while reading JSON result

If the user doesn't fill out the form correctly, I want to send an error message via ajax. Here is how I send the response to the browser using ajax: if($bo){ header('HTTP/1.1 400 Bad Request'); header('Content-Type: applicati ...

Create an unordered list using the <ul> tag

Creating a ul as input is my goal, similar to this example on jsfiddle: http://jsfiddle.net/hailwood/u8zj5/ (However, I want to avoid using the tagit plugin and implement it myself) I envision allowing users to enter text in the input field and upon hitt ...

When attempting to use JQuery autocomplete, the loading process continues indefinitely without successfully triggering the intended function

Currently, I am utilizing JQuery autocomplete to invoke a PHP function via AJAX. Below is the code snippet I am working with: $("#client").autocomplete("get_course_list.php", { width: 260, matchContains: true, selectFirst: false }); Upon execution, ...

Issue with MVC 4 Asynchronous File Upload: Controller Always Receiving Null Value

I'm encountering an issue while attempting to upload a file asynchronously from ajax to my controller. I am passing 3 variables - PictureId, PictureName, and PictureFile. The problem specifically lies with the "PictureFile" variable as it consistently ...

How can I populate a <select> tag with options dynamically using C# when the page loads?

I am using jQuery ajax to populate cascaded dropdown elements from a database. The issue I'm facing is that I can't seem to add the default "Select Program" option at the top of my first dropdown dynamically. Even though I tried using the prepend ...