简体   繁体   English

将变量从HTML页检索到.aspx页

[英]Retrieve variables from a HTML page into a .aspx page

I am currently making a game in HTML/javascript, and at the end of the game the user is asked to input their name into a textbox and press save score. 我目前正在用HTML / javascript制作游戏,在游戏结束时,要求用户将其名称输入文本框并按保存分数。 Is it possible to get the data on the inside of the text box and the score that is saved in a variable onto the .aspx page to save into my database? 是否可以在文本框的内部获取数据,并将分数保存在变量中,并将其保存到.aspx页上以保存到数据库中?

是的,您有可能必须获取值并将其发布到asp服务器端,以便可以将其保存在数据库中。

Here you go: 干得好:

$(document).ready(function () {
     $(document).on("submit", "#form", saveData);
});

function saveData(e) {
    e.preventDefault();
    $.ajax({
        type: 'POST',
        url: 'targetPage.aspx',
        data: {name: $("#inputName").val(), score: scoreVariable},
        success: alert("Score Saved")
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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