我正在尝试使用 $.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>"
我已经尝试了一周能找到的所有方法,但无法使其工作。
预先感谢您提供的任何帮助。
最佳答案
正当我准备上吊时,我让它开始工作了..;-)
我在这一行添加了 ,true) :
$( "#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 });
? 再次感谢您的帮助。
关于javascript - $().load() 不传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34398886/