select ajax,select2与ajax post方法

我正在尝试使用

select2与ajax加载.

这是我的代码:

clonedTemplate.find('[id^=detailsPhaseFinanceMinor_]').select2({

placeholder: "Select",minimumInputLength: 1,ajax: { // instead of writing the function to execute the request we use Select2's convenient helper

type: 'POST',contentType: "application/json; charset=utf-8",url: "mapBasic.aspx/GetFinSys",dataType: 'json',data: function (term,page) {

return "{'term':\"" + term + "\"}";

},results: function (data,page) { // parse the results into the format expected by Select2.

// since we are using custom formatting functions we do not need to alter remote JSON data

return { results: data.Value };

}

}

});

ajax调用是在同一页面的代码隐藏中的webmethod / pagemethod:

[WebMethod]

public static List GetFinSys(string term)

{

string stringToCompareTo = term.ToLower();

List result = new List();

// FIN SYS

using (mapEntities db = new mapEntities())

{

List finSysCodes = (from x in db.MPO_FINSYS_AMT

select x).ToList();

foreach (MPO_FINSYS_AMT item in finSysCodes)

{

string valKey = string.Format("{0}.{1}.{2}",item.FY,item.MDOT_MPO_CD,item.FIN_SYS);

LookupCodeItem x = new LookupCodeItem();

x.Value = valKey;

x.ShortDescription = string.Format("{0}.{1}.{2}",item.FIN_SYS); ;

x.LongDescription = string.Empty;

result.Add(x);

}

}

return result;

}

将数据输入到文本框中时,会发出POST请求,并且json发送似乎格式正确.

但是,pagemethod的响应是整个html页面.我的理解是,如果您没有在ajax调用中正确设置“contentType”,则可以通过post方法进行.我已经将它设置为与在页面上工作的所有其他ajax调用相同(它们不使用select2).

select2是否忽略“contentType”属性?还是还有别的东西我做错了?

看来它没有通过contentType通过.我能绕过selet2的内置ajax帮助器,并使用我自己手动定义的一个吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值