ajax类
2021-03-29 16:27
标签:length ons send mysql 字符 sub inf roc div 使用方法: ajax类 标签:length ons send mysql 字符 sub inf roc div 原文地址:https://www.cnblogs.com/feelyourbreath/p/12604670.html//recvType 有三个值HTML、XML和JSON , 默认为HTML,传值时不区分大小写
//bool 是一个boolean类型的值,true表示异步传输方式,false表示同步传输方式,默认为true
function Ajax(recvType, bool) {
var aj = new Object();
aj.targetUrl = ‘‘; //请求的地址 可以是PHP也可以XML文件
aj.sendString = ‘‘; //请求服务器传递的字符串 ? & 格式 url
if(typeof(bool)=="undefined")
aj.async=true;
else
aj.async=bool;
aj.recvType=recvType ? recvType.toUpperCase() : ‘HTML‘;//HTML XML JSON
aj.resultHandle = null;
aj.ff;
aj.createXMLHttpRequest = function() {
var request = false;
if(window.XMLHttpRequest) {
aj.ff=true;
request = new XMLHttpRequest();
if(request.overrideMimeType) {
request.overrideMimeType(‘text/xml‘);
}
} else if(window.ActiveXObject) {
aj.ff=false;
var versions = [‘Microsoft.XMLHTTP‘, ‘MSXML.XMLHTTP‘, ‘Microsoft.XMLHTTP‘, ‘Msxml2.XMLHTTP.7.0‘, ‘Msxml2.XMLHTTP.6.0‘, ‘Msxml2.XMLHTTP.5.0‘, ‘Msxml2.XMLHTTP.4.0‘, ‘MSXML2.XMLHTTP.3.0‘, ‘MSXML2.XMLHTTP‘];
for(var i=0; i
DOCTYPE html>
html>
head>
meta charset="UTF-8">
title>title>
script src="ajax.js" type="text/javascript" charset="utf-8">script>
head>
body>
form action="reg.php" method="post">
username:input onblur="show(this.value)" type="text" name="username"/>span id="userInfo">span>br />
password:input type="password" name="password"/>span id="username">span>br />
input type="submit" value="submit"/>
form>
body>
script type="text/javascript">
function show(username){
$aj = new Ajax();
var userInfo = document.getElementById(‘userInfo‘);
$aj.post(‘server.php‘,{username:username},function(data){
userInfo.innerHTML = data;
})
}
script>
html>
php
$mysqli = new mysqli(‘localhost‘,‘root‘,‘root‘,‘cms‘);
$result = $mysqli->query("select * from cms_manage where admin_user = ‘{$_POST["username"]}‘");
if($result->num_rows > 0){
echo $_POST[‘username‘].‘已存在‘;
}else{
echo $_POST[‘username‘].‘可以使用‘;
}