Я пытался передать вывод функции jquery в свой код на странице c #, чтобы выполнить некоторую обработку, и я не могу понять, как это сделать правильно, но я знаю, что это должно быть возможно.
Мой HTML-код выглядит следующим образом:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jQuery Get Selected Radio Button Value</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
var items = [];
$.each($("input[name]:checked"), function () {
items.push($(this).val());
});
$.ajax({
url: 'WebForm1.aspx/LoadStrings',
method: 'post',
contentType: 'application/json',
data: '{jsonString:' + items + '}',
dataType: 'json',
});
alert("You entered: " + items.join(", "));
});
});
</script>
</head>
<body>
<h4>Please select your gender.</h4>
<p>
<label>
<input type="radio" name="gender" value="male" />Male</label>
<label>
<input type="radio" name="gender" value="female" />Female</label>
<br />
<br />
<label>
<input type="radio" name="address" value="Kingston" />Kingston</label>
<label>
<input type="radio" name="address" value="Saint Catherine" />Saint Catherine</label>
</p>
<button type="button">Get Values</button>
</body>
</html>
Пожалуйста, помогите мне передать переменную 'items' из функции jquery в мой код,
[WebMethod]
public static string[] LoadStrings(string[] jsonString) {
}