我正在尝试返回多个值,如下所示,但一个值仅在成功时返回。
这就是我想要做的:
<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 (msg) {
$("#Result").text(msg.d);
}
});
$("#FontLists").change(function () {
$('#fonttype').val($('#FontLists option:selected').text());
});
});
</Script>
HTML:
Enter Text :<input id="sampletext" type="text" />
<select id="FontLists">
<option value="Aharoni">Aharoni</option>
<option value="Algerian">Algerian</option>
<option value="Andalus">Andalus</option>
</select>
<input id="fonttype" type="hidden" />
代码隐藏:
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
Public Shared Function Gettext(ByVal SampleText As String, ByVal FontType As String) As String
Return SampleText
Return FontType
End Function