Biu~~Biu
展开/收缩
java.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>2333</title> </head> <body> <input type="text" id="IDusername" name="username"> <input type="button" onclick="ButtonClick()" value="tijiao"> <script type = "text/javascript"> /*var Cstring; Cstring = "this is a test"; var Test; Test ="0000"; console.log(Cstring+Test);*/ function ButtonClick() { var user; user = document.getElementById("IDusername").value; var xmlhttp; if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest(); else xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); //get来AJ /*xmlhttp.open("GET","ajax.php?username="+user,false); xmlhttp.send(); var data=eval("("+xmlhttp.responseTexe+)"); //alert(xmlhttp.responseText); //user = document.getElementsByName("username").value; //alert(user+1); alert("user:"+data['name']+"pass:"+data['pass']); */ xmlhttp.open("POST","ajax.php?"+user,false); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("username="+user); var data=eval("("+xmlhttp.responseText+")"); alert("user:"+data['name']+"pass:"+data['pass']); } </script> </body> </html>
ajax.php
<?php /*if (isset ($_GET['username'])) //echo "zhanghu".$_GET['username']; { $name=$_GET['username']; $pass=rand(0,10000); $data['name']=$name; $data['pass']=$pass; echo json_encode($data); }*/ if (isset ($_POST['username'])) //echo "zhanghu".$_GET['username']; { $name=$_POST['username']; $pass=rand(0,10000); $data['name']=$name; $data['pass']=$pass; echo json_encode($data); } ?>
效果如下:
关于作者