简体   繁体   English

如何在ASP脚本中设置.data()变量,以便以后可以访问?

[英]How to set .data() variable inside an ASP script so it can be accessed later?

I am using $.post() to call an ASP script, which among other things has the following code: 我正在使用$.post()来调用ASP脚本,其中包括以下代码:

%>
    <script type="text/javascript">
    strTributeID = <% NTC %>
    $('body').data(tributeID, strTributeID);
    alert ($('body').data(tributeID));
    </script>
<%

Before the page is refreshed (so DOM data should not have been wiped out), I call another $.post() which does this upon success: 在刷新页面之前(因此不应该删除DOM数据),我调用了另一个$ .post(),它在成功时执行此操作:

var strTributeID = $('body').data(tributeID);

However, the value does not appear to be retained, or perhaps not set correctly. 但是,该值似乎没有保留,或者可能设置不正确。 What might be wrong? 可能是什么问题?

You are not writing the NTC value to the page, only evaluating it and throwing it away. 您不是将NTC值写入页面,而只是对其进行评估并将其丢弃。 Use the <%= tag: 使用<%=标记:

strTributeID = <%= NTC %>;

暂无
暂无

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

相关问题 以后可以访问添加到 javascript 数组中的数据吗? - Can data added in javascript arrays be accessed later? 保存HTML元素的数据,以便以后可以访问 - save data for an HTML element such that it can be accessed later 如何访问此脚本元素的数据? - How can the data of this script element be accessed? 回调 function 内部的变量集无法在外部访问 - Variable set inside of callback function can't be accessed outside React - 如何使用当前状态值作为变量,以便我可以将其设置为数组内的索引 - React - How to use the current state value as a variable so i can set as a index inside an array 如何在脚本标签内设置变量 - How to set a variable inside script tag 如何为我的背景设置一个变量以便稍后更改它而不将背景放入绘图中? 我想把它保存在设置中,这样它就不会重绘 - How can I set a variable for my background to change it later without putting background in draw? I want to keep it in setup so it doesn't redraw over 如何将获取数据存储到以后可以访问的全局变量中? - How to store fetch data into a global variable that you can access later? 如何将API响应存储到对象中,以便以后在脚本中使用它? - How do store API response into object so I can use it later in script? 应该如何声明一个空的时间戳变量,以便成为一个全局变量,以便我们稍后给它一个值? - How should an empty timestamp variable be declared, in order to be a global var so we can give it a value later?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM