[英]javascript : submit page onload
I have one signin page in which I can signin with username and password.Now I want to submit this page in the background.Like if user hit one url then user dont see signin page but its directly login ( hardcode credential as of now ) and see next page. 我有一个登录页面可以使用用户名和密码登录,现在我想在后台提交此页面,就像用户点击一个url一样,用户看不到登录页面而是直接登录(截至目前为硬编码凭证),参见下一页。
so in servlet response i am sending html / js so that browser send the http request with username and password. 所以在servlet响应中,我正在发送html / js,以便浏览器发送带有用户名和密码的http请求。
out.println("<body onload=\"submitForm()\"><form action=\""
+ rmHost
+ "/abc/signin method=\"post\">");
out.println("<input type=\"hidden\" name=\"username\" value=\""
+ username + "\" ><br>");
out.println("<input type=\"hidden\" name=\"password\" value=\""
+ password + "\"><br>");
out.println("<input type=\"hidden\" name=\"location\" value=\"\">");
out.println("</form> </body>
Using above code but browser is not send http post request to url.Is the above code correct. 使用以上代码,但浏览器未将http发布请求发送到url。以上代码正确。
If You are using jQuery You can do something like this 如果您使用的是jQuery,则可以执行以下操作
$(document).ready(function() {
$('#formID').submit();
});
it's a way better than using 'onload=\\"submitForm()' - this method is depricated. 这是比使用'onload = \\“ submitForm()'更好的方法-此方法已被描述。
You need to call the submit function of your form from js when body is loaded like this 像这样加载body时,需要从js调用表单的submit函数
document.getElementById('form-id').submit();
//form-id is the id of your form // form-id是表单的ID
Happy Coding :) 快乐编码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.