有关Aspx调用web方法的Select2的问题 [英] Question on Select2 with Aspx calling a webmethod

查看:84
本文介绍了有关Aspx调用web方法的Select2的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有ASPX的select2调用web方法。



这是我在页面上的控件

I am trying to use select2 with ASPX calling a webmethod.

this is my control on the page

<input type="hidden" id="attendee" style="width:300px;"/> 





这是我的javascript代码



this is my javascript code

$(document).ready(function () {

      $('#attendee').select2(
      {
          placeholder: 'Enter name',
          minimumInputLength: 1,
          allowClear: true,
          ajax:{
              type: "POST",
              url: "http://localhost:63830/project/TestClientPage2.aspx/GetClientList",
               dataType: 'json',
              data: function (term, page) {
                  return {
                      pageSize: 20,
                      pageNum: page,
                      searchTerm: term
                  };
              },
              results: function (data, page) {
                  //Used to determine whether or not there are more results available,
                  //and if requests for more data should be sent in the infinite scrolling
                  var more = (page * pageSize) &lt; data.Total;
                  return { results: data.results, more: more };
              }
          }


      });

  });





这是我的webmethod。



and this is my webmethod.

public static string GetClientList(string searchTerm)
{
    return @"{""employees"": [{ ""firstName"":""John"" , ""lastName"":""Doe"" }]}";
}





我遇到的问题是javascript没有调用webmethod。

谢谢



the issue i am having is that the javascript is not calling the webmethod.
thank you

推荐答案

(document).ready(function(){
(document).ready(function () {


' #scartdee')。select2(
{
占位符:' 输入名称'
minimumInputLength: 1
allowClear: true
ajax:{
type: POST
url: http:// localhost:63830 / project / TestClientPage2.aspx / GetClientList
dataType:' json'
数据:函数(术语,页面){
return {
pageSize: 20
pageNum:page,
searchTerm:term
};
},
结果:function(data,page){
// 已使用确定是否有更多可用结果,
// 以及是否有更多请求数据应以无限滚动方式发送
var more =(page * pageSize)& lt; data.Total;
return {results:data.results,more:more};
}
}


});

});
('#attendee').select2( { placeholder: 'Enter name', minimumInputLength: 1, allowClear: true, ajax:{ type: "POST", url: "http://localhost:63830/project/TestClientPage2.aspx/GetClientList", dataType: 'json', data: function (term, page) { return { pageSize: 20, pageNum: page, searchTerm: term }; }, results: function (data, page) { //Used to determine whether or not there are more results available, //and if requests for more data should be sent in the infinite scrolling var more = (page * pageSize) &lt; data.Total; return { results: data.results, more: more }; } } }); });





这是我的webmethod。



and this is my webmethod.

public static string GetClientList(string searchTerm)
{
    return @"{""employees"": [{ ""firstName"":""John"" , ""lastName"":""Doe"" }]}";
}





我遇到的问题是javascript没有调用webmethod。

谢谢



the issue i am having is that the javascript is not calling the webmethod.
thank you


什么是 select2()



依据对于代码,它是一个驻留在任何插件内的函数。

你有没有调用任何插件



下一步是,您需要查看 Developer Tool的控制台选项卡,列出是否有任何错误。

它会给你关于你目前面临的问题的提示,你可以在代码中轻松纠正它们。



您也可以通过编写调试器来调试代码; 在代码中,并尝试检查所有值是否正确。
What is select2()?

According to the code, it is a function which resides inside any Plugin.
Have you called any Plugin?

Next thing is, you need to see the Developer Tool's console tab, of there are any errors listed or not.
It will give you the hint about the issues you are facing currently and you can easily rectify them in code.

You can also debug the code by just writing debugger; inside the code and try to check if all the values are correct or not.


这篇关于有关Aspx调用web方法的Select2的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆