Transferring information from JavaScript to ASP.NET Datatable via AJAX communication

I've been working on a JavaScript code that validates user input against data from a local database through AJAX calls.

<script type="text/javascript">
   var button = document.querySelector("#next");
   var data = (<%=this.json%>); var count = data.sub.length;
   var ans = data.sub[answerPointer].answ;

   button.addEventListener('click', function() {
       imagePointer++;
       answerPointer++;
       updateImage();
       updateAnswer();
   });
   (function check () {
       'use strict';

       var snackbarContainer = document.querySelector('#demo-toast-example');
       var showToastButton = document.querySelector('#demo-show-toast');
       showToastButton.addEventListener('click', function () {
           'use strict';

           var x = document.getElementById("numb").value;
           if (x == ans) {
               var text = "Correct answer, good job!";
           }
           else {
               var text = "Incorrect, try again!";
           }
           var data = { message: text};
           snackbarContainer.MaterialSnackbar.showSnackbar(data);

       });
   }());

Some of the code has been omitted for clarity.

Now, my query is how can I transmit data (such as adding "true" or "false" to a specific column) to the server-side of the ASPX page.

Answer №1

Important Reminder

Validating answers on the client-side (using JavaScript code) is not secure.

A malicious user can access the answers and send them to a server or even manipulate AJAX requests to the back-end, falsely confirming that all answers are correct.

It's safer to send the answer to the server for verification.

Furthermore, you cannot make an AJAX request directly to an ASPX page. You would need an ASMX service to handle those requests. If you're unsure how to do this, you can refer to this helpful resource: jQuery ajax request from asmx web service.

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

Creating a progress bar with a circular indicator at the completion point

Looking to create a unique horizontal progress bar with a circle at the end using react js, similar to the image provided. Successfully implemented a custom "%" progress bar and now aiming to incorporate a circle with text inside at the end. https://i.sst ...

Is there a way to halt the polling process for the specific API handling the background task?

I have been using this polling function for executing background tasks. export const poll = ({ fn = () => {}, validate = (result) => !!result, interval = 1000, maxAttempts = 15, }) => { let attempts = 1; // eslint-disable-next-line con ...

Enhancing Performance of AJAX AutoComplete feature in ASP.NET using C#

One issue is that the list of suggestions appears far below the actual text box. Refer to the image for clarification. The second problem is that there is a delay of one to two seconds before any results are displayed using auto completion. This delay doe ...

What is the appropriate way to incorporate a dash into an object key when working with JavaScript?

Every time I attempt to utilize a code snippet like the one below: jQuery.post("http://mywebsite.com/", { array-key: "hello" }); An error message pops up saying: Uncaught SyntaxError: Unexpected token - I have experimented with adding quotation m ...

Updating all the direct components within the corresponding category with jQuery

Here is the HTML content I am working with: <li class="info"> info<li> <li class="other"> info<li> <li class="other"> info<li> <li class="Error"> error<li> <li class="other"> error<li> < ...

Exploring the Bookmarking Capabilities of Firefox

Is there a way to access the users' bookmarks using Firefox API and javascript? Appreciate any help, Bruno ...

Having trouble launching a Firefox browser instance for testing with Visual Studio, C#, Nunit, and Selenium

I am encountering some issues while attempting to execute a basic UI test in Visual Studio (version 16.11.10) using C# and NUnit. The versions of Selenium.Firefox.WebDriver, Selenium.WebDriver, and Selenium.Support that I am using are 0.27.0, 4.1.0, and 4. ...

Replace a portion of text with a RxJS countdown timer

I am currently working on integrating a countdown timer using rxjs in my angular 12 project. Here is what I have in my typescript file: let timeLeft$ = interval(1000).pipe( map(x => this.calcTimeDiff(orderCutOffTime)), shareReplay(1) ); The calcTim ...

Calculating the Bounding Box of SVG Group Elements

Today I encountered a puzzling scenario involving bounding box calculations, and it seems that I have yet to fully understand the situation. To clarify, a bounding box is described as the smallest box in which an untransformed element can fit within. I h ...

Two functions that require multiple clicks to execute

My JavaScript code requires two consecutive clicks to function properly for some reason. Here is the code for the link: <a href="" onclick="select_all_com(); return false">Select All</a> Now, here is the code for the function that is called w ...

Error encountered with special character encoding in ajax request

When attempting to retrieve a JSON file with special characters through an AJAX call, some of the characters are being converted to in the success callback. The content-type has been set as: application/json;charset=UTF-8. Here is the content of the m ...

Error with HTML5 Audio API: "unable to construct AudioContext due to unavailable audio resources"

Currently, I am attempting to develop a visualization similar to a graphic equalizer for HTML5 audio in Chrome using webkitAudioContext. However, I have encountered some unexpected behavior when trying to switch the audio source, such as playing a differen ...

Extracting public data from social media profiles as displayed in Smartr

Is there any pre-existing API or reference material available for achieving this task? I am interested in accessing public social data without the need for users to manually link their accounts to our site. ...

JavaScript inheritance through prototypes and the properties of objects

I am currently exploring the concept of prototyped inheritance in JavaScript for a function. This process is well documented in Wikipedia's javascript article. It functions smoothly when dealing with simple JavaScript types: function Person() { t ...

When trying to access document.cookie, an empty string is returned despite the presence of cookies listed in developer tools, and the httpOnly flag is set

There are times when I encounter an empty string while trying to access document.cookie on the login page, despite the following conditions being met: The cookies are visible in the Chrome and Firefox developer tools, The httpOnly flag of the cookie I&ap ...

Limiting the character count in a textarea can be achieved by implementing the 'jQuery InlineEdit' feature

Currently, I am utilizing the jquery.inlineedit.js plugin for inline editing, and one of my requirements is to limit the maximum length of text within the textarea. I have attempted to use other popular jQuery scripts for this purpose, but unfortunately, I ...

Using Json.NET to Append JObject to existing JArray

Struggling with a seemingly simple piece of code, can't seem to figure it out. JObject obj = new JObject { "Name", "John" }; JArray array = new JArray(); array.Add(obj); // receiving error message: "Can not add Newtonsoft.Json.Linq.JValue to Newtons ...

transition effect of appearing and disappearing div

Having trouble creating a fade out followed by a fade in effect on a div element. The fade out happens too quickly and the fade in interrupts it abruptly. Here is the JavaScript code: $('#fillBg').stop(true,false).fadeTo(3000, 0); $("#fillBg"). ...

Invalid character entered into HTML5 number input field

How can I validate a number field on my own when element.value returns nothing in Chrome if the content is alphabetical? Setting 'novalidate' on the form does not prevent this issue. As a result, I am unable to distinguish between an empty entry ...

How can I create an Onclick function that works for multiple buttons sharing the same ID?

Having an issue with a component that loads data using buttons. I have a function that updates the state/variable based on the button ID, but since all button IDs are the same, it only works for the first button... I'm struggling to assign unique IDs ...