1
我试图在WebForms中使用jQuery Validator插件。这里是我的jQuery代码:与ASP.NET WebForms的jQuery验证器#远程
$("input[id$=FromZip]").rules('add', {
required: true,
postalCode: true,
remote: {
url: "shipping companies.aspx/ValidatePostalCode",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: "{'postalCodeToValidate': '" + $("input[id$=FromZip]").val() + "'}",
dataFilter: function(data) { return (JSON.parse(data)).d; }
},
messages: {
required: '"From" zip code is required.',
postalCode: 'Invalid "From" zip code',
remote: 'The "From" zip code was not found in the database.'
}
});
这样做的问题是,val()
总是返回空的,所以价值总是被标记为假。我尝试它包裹在一个函数调用,就像这样:
remote: function() {
var r = {
url: "shipping companies.aspx/ValidatePostalCode",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: 'json',
async: false,
data: "{'postalCodeToValidate': '" + $("input[id$=FromZip]").val() + "'}",
dataFilter: function(data) { return (JSON.parse(data)).d; }
}
}
除了现在的WebMethod不会被调用都没有Ajax请求被提出,而在此之前(不含var r = {}
东西)呼叫在而是传递空数据而不是来自文本框的值。我一直试图找出现在这一天的好日子。
有什么建议吗?
遥控功能,所以我似乎已经通过创建一个自定义的方法,而不是使用远程部分解决了这个问题,但现在它的标记领域,即使响应,我得到为无效从服务器返回的是:{“d”:“true”}。即使在自定义方法中对“真”值进行硬编码仍然会将该字段标记为无效! – 2011-01-21 14:14:36