通过Javascript、How将Dropdownlist索引作为参数发送给WS
send Dropdownlist index as a parameter to WS thru Javascript, How?
我正试图用Jquery Autocomplete:向我的WS发送两个参数
- 文本框,我想要完成的位置
- 下拉列表索引
我在获取dropdownlist索引时遇到了问题,因为我只获取Controller的名称。
这是我的脚本:
<script type="text/javascript" language="javascript">
$(function() {
$('#<%= TextBoxes1.ClientID%>').autocomplete({
source: function (request, response) {
$.ajax({
url: "WB/EmployeeService.asmx/GetEmpolyeeId",
data: "{ 'Text': '" + request.term + "','SelectedIndex':'" + '#<%= DP1.ClientID %>' + "'}",
type: "POST",
dataType: "json",
contentType: "application/json;charset=utf-8",
success: function (result) {
response(result.d);
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
minLength: 0
});
});
</script>
这是我的WS-
public List<string> GetEmpolyeeId(string Text, string SelectedIndex)
我需要做些什么才能让它发挥作用?
您需要下面的2,正如您在问题中提到的那样。
- 文本框,我想要完成的地方--
request.term
,您使用它是正确的 - dropdownlist索引——假设dropdownlist-id是
DP1
,您需要使用以下方法获取其索引
$("#<%= DP1.ClientID %>")[0].selectedIndex
所以把所有的东西放在一条线上,
data: "{ 'Text': '" + request.term + "','SelectedIndex':'" + $("#<%= DP1.ClientID %>")[0].selectedIndex + "'}",
示例
function OnChangeVal() {
alert($("#sel")[0].selectedIndex);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select onchange="OnChangeVal()" id="sel">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
我搞定了!!:-)
这就是我所做的:
<script type="text/javascript" language="javascript">
var ddl = document.getElementById('<%=DP1.ClientID%>');
$(function () {
$('#<%= TextBoxes1.ClientID%>').autocomplete({
source: function (request, response) {
$.ajax({
url: "WB/EmployeeService.asmx/GetEmployeeDetails",
data: "{ 'Text': '" + request.term + "','SelectedIndex':'" + ddl.selectedIndex <%--'#<%= DP1.ClientID %>'--%> + "'}",
type: "POST",
dataType: "json",
contentType: "application/json;charset=utf-8",
success: function (result) {
response(result.d);
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
minLength: 0
});
});
</script>
我在"data"(Dropdownlist索引)中添加了一个变量,而我在进入函数之前定义了Dropdownlist。
WS也遇到了同样的问题。
相关文章:
- 函数参数中的数据与指定变量之间的任何性能差异
- 使用Express捕获参数
- 参数变量出现ngTable指令问题
- AngularJS:我可以跳过函数参数回调吗
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 要求未定义JS回调参数
- 我的jQuery插件参数没有正确启动,遇到了问题
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- jquery设置为使用参数运行
- Javascript”;类“;带有参数的扩展
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 函数未将值作为参数传递
- 如何将参数传递到angularJs中的工厂
- JS:检查URL中的参数,然后迭代一个参数为var的函数
- 正在传递JSONP标头's数据参数到另一个文件中的AJAX请求
- MVC 3页面导航和使用javascript传递参数
- 从查询字符串参数推断出正确的数据类型
- 传递包含'%的参数'在URL中
- 为什么不'我们在javascript中使用函数参数的数据类型
- 通过Javascript、How将Dropdownlist索引作为参数发送给WS