我正在寻找将我在文本框中搜索的输入连接到$ .ajax-data中。 textbox id = textSearchTB。
(此功能的整个想法是按文本框输入中的搜索,并显示结果)
function getSearchRecipe() {
$.ajax({
url: "WebService.asmx/searchRecipe",
data: "{id:textSearchTB}",
type: "POST",
dataType: 'json',
contentType: "application/json; charset= tf-8",
success: function (data) {
var result;
if (data.hasOwnProperty('d')) {
result = data.d;
}
else {
result = data;
}
for (i = 0; i < result.length; i++) {
$("#searchResult").append("<div>'" + result[i] + "'</div>");
}
}
});
}
<div data-role="content">
<form id="searchF">
<input type="text" id="textSearchTB"/>
<input id="searchRecipeBTN" type="submit" value="חפש מתכון" onclick="getSearchRecipe()" />
</form>
<form id="searchResult">
</form>
</div>
答案 0 :(得分:0)
要在搜索框中获取值,请执行以下操作:
var textInput = $('#textSearchTB').val(); // Jquery
然后:
data: {id: textInput} // am assuming that the server side method contains an argument named "id"