$()。load()不传递变量

时间:2015-12-21 15:14:40

标签: javascript jquery

我正在尝试使用$.load()传递一个变量,但变量没有完成。这是从嵌入表单设置变量的代码:

'first of all determine whether there are any records
If Recordset.EOF Then
    Response.Write("No records returned.")
Else
    'if there are records then loop through the fields
%>

<form action =""> 
    <select onchange="showCustomer(this.value)">
        <option selected="selected" disabled="disabled">Select a Transponder:</option>
        <%
            Do While NOT Recordset.Eof     
                ' list xpdrs %>
                <option value="<%=Recordset("Transponder")%>"><%=Recordset("Transponder")%></option>
            <% 
    </select>
</form>

然后我尝试调用一个文件,传递变量并使用以下代码将其加载到<div>

<div id="chartDiv" style="float:left; padding: 25px; margin-left:200px;height:700px;width:1200px;border:1px solid green "></div>
<script>
    function showCustomer(str) {
        //alert("Function showCustomer triggered!!  String is: " + str);
        $("#chartDiv").load("asp-query.asp?q=" + str);
    }
</script>

该变量然后是第二个文件中SQL查询的一部分:

'declare the SQL statement that will query the database
SQL = "SELECT  TOP 1 [uid], [Satellite],[Transponder],[Carrier], " &_
    "[Trace],[startfreq],[stopfreq], [traceTime], [minval],[maxval],[numpoints],[reflevel] FROM [PlotMinder].[dbo].[tblTrace] " &_
    "WHERE [Transponder] = " &  "'" & request.querystring("q") & "'"

response.write SQL & "<BR>"

我已经尝试了一周我能找到的所有东西,但是无法使其发挥作用 提前感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:0)

我得到了它的工作,就像我准备自己挂起..; - )

我添加了,真的)到这一行:

$( "#chartDiv" ).load( "asp-query.asp?q=" +str, true);

它有效。它来自原始功能

function showCustomer(str) {
  var xhttp;    
  if (str == "") {
    document.getElementById("txtHint").innerHTML = "";
    return;
  }
  xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
      document.getElementById("txtHint").innerHTML = xhttp.responseText;

    }
  };
  xhttp.open("GET", "asp-query.asp?q="+str, true);
  xhttp.send();

}

不确定为什么该更改会使函数工作(传递变量)。如果有人有答案,我想解释一下。另外,@ basil与行

有类似的方法
$("#chartDiv").load('asp-query.asp', { q: str });

? 再次感谢您的帮助。

相关问题