简体   繁体   中英

Sending data from JS to ASP.NET-datatable using AJAX

I have the following JS code that checks if a user input is matching the data from the datatable pulled from a local DB using AJAX

<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 = "תשובה נכונה, כל הכבוד!";
           }
           else {
               var text = "טעות, נסה שוב!";
           }
           var data = { message: text};
           snackbarContainer.MaterialSnackbar.showSnackbar(data);

       });
   }());

Some of the code is missing in order to reduce clutter.

My question is, how can I send data(like adding "true" or "false" into a specific column) to the server side of the aspx page.

Note

Verifying answers on client-side (in js code) is not save.

A malicious user can view the answers and send them to service or even call send AJAX queries to back-end stating that all answers is good.

So I would better send answer to server and did verification there.

Anyway, you cannot send ajax request to ASPX page. For this you need and ASMX service to accept requests. Having it you can send requires like stated in related question - jQuery ajax request from asmx web service .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM