要闡述我的意見的前面,你可以做這樣的事情與jQuery(雖然你更有意義的代碼) -
$("some button you have on your form").click(function() {
$.ajax({
url: "url of the script that will perform the validation?val1=something&val2=something&val3=something",
success: function(data) {
//Here, do something with the returned 'data' from your validation script
//This could be highlighting incorrect data, or filling form fields with
//new data of some kind...
}
});
});
這將是最簡單的一種設置來獲得你想要的東西。有關ajax如何在jQuery中工作的更多詳細信息,請參閱go here。
在您的經典asp代碼中,您只需處理由ajax函數發送的數據並返回一些內容(通過response.write(xxxx)),它將被髮送回調用函數並由函數中的代碼處理(data),使用'data'變量來訪問返回的值。
您的代碼可能看起來像這樣基於上述發送Ajax請求的類型: -
<%
if request.querystring("val1") = something then
'do something with the data
end if
'Etc
Response.write(some kind of response that you can deal with in the calling function)
%>
你有沒有想過,也許使用jQuery AJAX將數據發送到驗證腳本,然後響應處理?這樣用戶不必離開頁面。 – 2013-05-02 20:01:30
我同意,用ajax和jQuery來做。 – 2013-05-02 20:07:05
好的。我不熟悉這種方法。它的主旨是什麼?從我的表單腳本中執行我的驗證腳本,它會向我發回類似於請求的內容? – user1417467 2013-05-02 20:26:34