我目前正在处理一些需要发布到 asp 验证脚本的页面,然后将数据(尚未保存到数据库)重新填充到表单上各自的元素中。
我只是打算为此使用 session 变量,但由于表单设置为具有动态生成的元素,我认为它会导致网站崩溃,具体取决于生成这些元素的数量。截至目前,我正在从脚本 A 发布到脚本 B,然后重定向回脚本 A。
我打算简单地获取 Request.Form 元素并将它们放入脚本 B 中的 session 中,验证,然后重定向到脚本 A。然后在脚本 A 中使用我的 request.form 元素循环遍历 session 变量,然后拍打那些回到各自的元素。任何想法将不胜感激。
我正在研究类似 Server.Execute 的东西,但我没有使用过它,所以我不熟悉它。提前致谢。
最佳答案
为了详细说明我之前的评论,您可以使用 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)),这些内容将被发送回调用函数并由 function(数据),使用“数据”变量访问返回值。
根据上面发送的 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)
%>
关于javascript - 在没有 session 变量的情况下在经典 asp 中发布和取回 html 元素进行验证的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16346653/