如何将JavaScript变量值传递给经典ASP变量



html:

<div>
<select type="text" id="filterType" class="myInput">
    <option id="one">one</option>
    <option id="two">two</option>
    <option id="three">three</option>
</select>
</div>

JS:

var currentFilterDropDownOpt;
$("#filterType").change(function(){
    currentFilterDropDownOpt = $(this).val();
});

我想将此CurrentFilterDropDownOpt设置为我的ASP变量。

asp:

<%
    DIM filterDD
    filterDD = currentFilterDropDownOpt; //something like this
%>

有人可以提供帮助吗?

tia

JS是客户端,ASP是服务器端。您不能将客户端生成的变量直接传输到服务器端脚本。如果您确实需要通过ASP处理变量,则应通过异步请求将其发送到服务器,并通过JS处理响应。

例如

$("#filterType").change(function(){
  var currentFilterDropDownOpt = $(this).val();
  $.ajax("YOUR_SERVER_LOCATION?currentFilterDropDownOpt="+currentFilterDropDownOpt, {
    success: function(data) {
       //do something with the response
    },
    error: function() {
       //do something if there is an error
    }
  });
});

最新更新