用img标签实现数据提交
其实不一定要使用script标签,用img标签也可以实现。(如果远端要回传大量数据,而不是bool类型的标志,则需要使用script标签)。
把下面代码保存到本地html,用户名:"dexterfar"。密码:"888"。就能收到成功消息。
- HTML code
-
<script> function login(name,pass) { var img = document.createElement("img"); img.src = "https://www.chenre.cn/test2.aspx?name="+encodeURI(name)+"&password="+encodeURI(pass); img.style.visibility = "hidden"; img.style.height = "1px"; img.style.width = "1px"; img.onerror = function() { //Finish Code Here alert("Err"); } img.onload = function() { //Finish Code Here alert("Ok") } document.body.appendChild(img); } </script> <body> 用户名:<input name="" id="name" type="text" /> 密码:<input name="" id="password" type="password" /> <input name="" value="登录" type="button" onclick="login(document.getElementById('name').value,document.getElementById('password').value)" /> </body>
最后更新:2017-04-02 06:51:53