Search code examples
javascriptjqueryasp-classiccallbackjquery-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:

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


Solution

  • You are not writing the NTC value to the page, only evaluating it and throwing it away. Use the <%= tag:

    strTributeID = <%= NTC %>;