現在,我的表單只有一個簡單的輸入。我試圖使用jQuery Validate的遠程部分來調用我的web服務,它現在只是返回false。我現在遇到的問題是,當它調用我的web服務時,它正在拉取由.net創建的垃圾輸入的名稱。有沒有辦法來覆蓋這個,並使用輸入的Id和輸入的名稱。這裏是我的jQuery:jQuery使用WebForms和WebService進行驗證
$(function() {
$('form').validate();
$("#tbSiteName").rules("add", {
required: true,
remote: "webservices/webservice.asmx/HelloWorld"
});
});
這裏是我的HTML:
<label for="tbSiteName">Name:</label>
<input name="ctl00$MainContent$tbSiteName" type="text" id="tbSiteName" class="required" />
下面是從Chrome中的頭信息:(注意查詢字符串PARAMS)
Accept:application/json, text/javascript, */*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Type:application/x-www-form-urlencoded
Cookie:ASP.NET_SessionId=qvupxcrg0yukekkni323dapj
Host:localhost:56803
Referer:http://localhost:56803/Default.aspx
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10
X-Requested-With:XMLHttpRequest
Query String Parameters
ctl00%24MainContent%24tbSiteName:ts
從服務器端我收到500內部服務器錯誤,因爲我的簽名與我的帖子不符。
Webservice的代碼:
[WebMethod]
[ScriptMethod]
public bool HelloWorld(string tbSiteName) {
return tbSiteName.Length > 5;
}
感謝您的幫助。