これは、SQL Server 2012データベースを使用するIIS 7.5 Classic ASP Webサイト上にあります。SQL文でAJAXを2つ使用する
私は助けが必要です。私は2つの値を別の古典的なaspページに渡しています。これは、SQL文でこれらの値を使用して値を返します。
これを使用すると値は返されませんが、 UnitPieces
の場合は '7'、City
の場合は 'Los Angeles'のように、SQL Serverデータベースから適切なデータを返します。ここで
は、私は、このAJAX機能に値を送信し
<form>
<select id="shiptoarea" name="shipcost" class="required" onchange="shipping(this.value)">
<option disabled="disabled" selected="selected" value="">--Choose One--</option>
<option value="San Francisco">San Francisco</option>
<option value="Los Angeles">Los Angeles</option>
<option value="New York">New York</option>
<option value="San Diego">San Digeo</option>
</select>
</form>
<p id="shippingcost"></p>
で働いているものです(注:<% = vcItems%>は、ショッピングカート内のアイテムの数です)
function shipping(str) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
document.getElementById("shippingcost").innerHTML = this.responseText;
};
xmlhttp.open("GET", "shiptoamount.asp?y=<%=vcItems%>&q=" + str, true);
xmlhttp.send();
}
</script>
そして、これは、SQLクエリを実行するページです
Dim Connection
Dim ConnString
Dim Recordset
Dim SQL
Dim qq
Dim yy
qq = (request.querystring("q"))
yy = (request.querystring("y"))
ConnString = "DRIVER={SQL Server};SERVER=SQLServerName;UID=username;" & _
"PWD=password;DATABASE=databasename"
SQL = "SELECT FlatShipCost FROM ShipRates WHERE UnitPieces = "&yy&" AND City = "&qq
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.Open ConnString
Recordset.Open SQL,Connection
If Recordset.EOF Then
Response.Write("No records returned.")
Else
if NOT Recordset.Eof then
Response.write (request.querystring("q"))
Response.write (Recordset("FlatShipCost"))
end if
End if
Recordset.Close
Set Recordset = nothing
Connection.Close
Set Connection = nothing
奇妙なことがあり、もし私手動
Response.write (request.querystring("q"))
または
Response.write (request.querystring("y"))
ITドロップダウンから選択City
ためのHTMLとも<%からカート内のアイテムの正しい数を表示するDOES = vcItems%>。したがって、値はクエリを実行しているページに到達していますが、私はSQL文に間違ったことをしている可能性があります。助けてください。事前のおかげで
は(https://xkcd.com/327/) –