我正在尝试使用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:
<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上放置一个断点时,它会显示我,如下面的屏幕截图所示:
答案 0 :(得分:0)
我找到了一种方法:
success: function (response) {
var result1 = (response.d.SampleText), result2 =(response.d.FontType),
result = "SampleText: " + result1 + " FontType: " + result2;
$("#Result").html(result);
}
在此之前,我已遵循此way来实现