我正在尝试使用 ajax 调用来调用 webmethod,如下所示:
<script type="text/javascript">
$(document).ready(function () {
$("#getdetails").click(function () {
$.ajax({
type: "POST",
url: "Default.aspx/Gettext",
data: JSON.stringify({SampleText: $('#sampletext').val(), FontType: $('#fonttype').val() }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$("#Result").html(response.d);
}//success
});//ajax call
});//button click
$("#FontLists").change(function () {
$('#fonttype').val($('#FontLists option:selected').text());
});
});//document
网络方法:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
Public Shared Function Gettext(ByVal SampleText As String, ByVal FontType As String) As String
Dim List1 As New ArrayList()
List1.Add(SampleText)
List1.Add(FontType)
For Each Str As String In List1
Return Str
Next
End Function
现在的问题是,当我单击按钮时,响应只显示文本而不是选定的字体。但是当我通过在 List1 放置断点看到它时,它显示了我,如下面的屏幕截图所示: