简体   繁体   中英

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:

%>
    <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:

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. Use the <%= tag:

strTributeID = <%= NTC %>;

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