カスケードドロップボックスのペアの内容に基づいてSQLデータベースをクエリするjQueryを介してWebメソッドを実行しようとしています。メソッドを呼び出して、さまざまなjQueriesを使用して結果を取得しようとしましたが、ある時点でUpdatePanelを使用して機能させようとしましたが、各試行の最後に同じポイントに留まっているようで、すべてのコードがエラーなしで実行されますただし、最終的なラベルテキストに渡される結果文字列は空白です。
WebMethodで非常に初歩的な何かを見逃していて、誰かが私を正しい方向に向けることができるかどうか疑問に思ったのではないかと思います。
データベース内のドライバーと呼ばれるターゲットテーブルには、次の4つの列があります。
model_id、整数、ddlModel.SelectedItem.Value
モデル、varchar(255)、ddlModel.SelectedItem.Text
ドライバー、整数(ビットは試行されましたが、問題に影響はありません。interはで使用されます。レコード作成ページを正しく実行できるようにするため)。これには、結果文字列
subsでsubsフィールドを使用するかどうかを定義する1または0が含まれ、varchar(255)には、結果文字列に追加されるデータが含まれます。ドライバーが0の場合
カスケードドロップダウンボックスに入力するために使用されるテーブルは正しく機能しているように見えるため、詳細は説明していませんが、この情報やその他の情報が必要な場合は、遠慮なくお問い合わせください。
私のコードは次のとおりです。
printers.asmx.vb
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.Specialized
Imports AjaxControlToolkit
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
<WebService(Namespace:="http://printers.mydomainname.com/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class printers
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function GetMake(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim strConnection As String = ConfigurationManager.ConnectionStrings("PrinterConnection").ConnectionString
Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
Dim strMakeQuery As String = "SELECT * FROM manufacturers ORDER BY make ASC"
Dim cmdFetchMake As SqlCommand = New SqlCommand(strMakeQuery, sqlConn)
Dim dtrMake As SqlDataReader
Dim myMake As New List(Of CascadingDropDownNameValue)
sqlConn.Open()
dtrMake = cmdFetchMake.ExecuteReader
While dtrMake.Read()
Dim strMakeName As String = dtrMake("make").ToString
Dim strMakeId As String = dtrMake("make_id").ToString
myMake.Add(New CascadingDropDownNameValue(strMakeName, strMakeId))
End While
Return myMake.ToArray
End Function
<WebMethod()> _
Public Function GetModel(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim strConnection As String = ConfigurationManager.ConnectionStrings("PrinterConnection").ConnectionString
Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
Dim strModelQuery As String = "SELECT * FROM printers WHERE make_id = @makeid"
Dim cmdFetchModel As SqlCommand = New SqlCommand(strModelQuery, sqlConn)
Dim dtrModel As SqlDataReader
Dim kvModel As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)
Dim intMakeId As Integer
If Not kvModel.ContainsKey("make") Or Not Int32.TryParse(kvModel("make"), intMakeId) Then
Return Nothing
End If
cmdFetchModel.Parameters.AddWithValue("@makeid", intMakeId)
Dim myModel As New List(Of CascadingDropDownNameValue)
sqlConn.Open()
dtrModel = cmdFetchModel.ExecuteReader
While dtrModel.Read()
Dim strModelName As String = dtrModel("model").ToString
Dim strModelId As String = dtrModel("model_id").ToString
myModel.Add(New CascadingDropDownNameValue(strModelName, strModelId))
End While
Return myModel.ToArray
End Function
<WebMethod()> _
Public Function GetDriver(ByVal model As String) As String
Dim strConnection As String = ConfigurationManager.ConnectionStrings("PrinterConnection").ConnectionString
Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
Dim strDriverQuery As String = "SELECT * FROM drivers WHERE model = @model"
Dim cmdFetchDriver As SqlCommand = New SqlCommand(strDriverQuery, sqlConn)
Dim dtrDriver As SqlDataReader
Dim intModel As Integer
cmdFetchDriver.Parameters.AddWithValue("@model", intModel)
Dim strResult As String = "The selected printer is"
sqlConn.Open()
dtrDriver = cmdFetchDriver.ExecuteReader
dtrDriver.Read()
Dim intDriver As Integer = dtrDriver("driver")
Dim strSubs As String = dtrDriver("subs").ToString
If intDriver = 1 Then
strResult = strResult + "fully compatible with the Windows 2003 Hosted platform."
Else
strResult = strResult + "supported on the Windows 2003 Hosted platform via a subsituted driver:" + strSubs
End If
Return strResult
End Function
End Class
default.aspx
<%@ Page Language="VB" AutoEventWireup="false" EnableEventValidation="false" Inherits="Printer_Compatibility_Matrix_VB._Default" Codebehind="Default.aspx.vb" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Printer Compatibility Matrix</title>
<script src="jquery-1.4.4.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function CallService() {
$.ajax({
type: "POST",
url: "printers.asmx/GetDriver",
data: $("#ddlModel option:selected").text(),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError
});
}
function OnSuccess(data, status) {
$("#lblResult").html(data.d);
}
function OnError(request, status, error) {
$("#lblResult").html(request.statusText);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods = "true">
<Services>
<asp:ServiceReference Path="printers.asmx" />
</Services>
</asp:ScriptManager>
<div>
Manufacturer: <asp:DropDownList ID="ddlMake" runat="server" Width="170" /><br />
Printer: <asp:DropDownList ID="ddlModel" runat="server" Width="170" /><br />
<asp:Button ID="btnDriver" Text="Submit" OnClientClick="CallService(); return false;" runat="server" />
<asp:Label ID="lblResult" Text=" " Width="100%" runat="server" />
<cc1:CascadingDropDown
id="CascadingDropDown1"
runat="server"
category="Make"
prompttext="Select a Manufacturer..."
ServiceMethod="GetMake"
ServicePath="printers.asmx"
TargetControlId="ddlMake"
/>
<cc1:CascadingDropDown
id="CascadingDropDown2"
runat="server"
category="Model"
prompttext="Select a Printer..."
ServiceMethod="GetModel"
ServicePath="printers.asmx"
TargetControlId="ddlModel"
ParentControlId="ddlMake"
/>
</div>
</form>
</body>
</html>
お時間をいただき、ありがとうございました。
ジム
編集
Frédéricによって発見されたエラーに加えて、jQueryを参照することも忘れていたようです。これらのエラーに基づいて、現在の反復に一致するように上記のコードを修正しました。
現在の状態では、ラベルテキストに「内部サーバーエラー」が返されます。このコードで単純な「HelloWorld」を呼び出そうとしても、ラベルに空白の結果が返されるため、Javaと関係があると思われます。