用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