Home  >  Article  >  Backend Development  >  Basic operations related to AJAX

Basic operations related to AJAX

一个新手
一个新手Original
2017-09-14 09:16:041095browse

AJAX development

AJAX is "Asynchronous Javascript And XML” (asynchronous JavaScript and XML) refers to a web development technology for creating interactive web applications.

AJAX = Asynchronous JavaScript and XML (a subset of Standard Universal Markup Language).

AJAX is a technology for creating fast, dynamic web pages.

By exchanging a small amount of data with the server in the background, AJAX can enable asynchronous updates of web pages. This means that parts of a web page can be updated without reloading the entire page.

Traditional web pages (not using AJAX) must reload the entire web page if the content needs to be updated.

AJAX application example

1. Prompt for user name in the registration interface

The effect is as shown in the figure:

The code is as follows:

<!DOCTYPE html>
<html>    
<head>        
<meta charset="UTF-8">        
<title></title>        
<script src="bootstrap/js/jquery-1.11.2.min.js"></script>    
</head>    
<body>        
<input type="text" id="uid" />         
<span id="test"></span>           
 </body>    
 <script>//Ajax//用户注册名提示
 $("#uid").blur(function(){    //取用户名    
 var uid = $(this).val();    //去数据库看用户是否存在    
 $.ajax({        url:"yhmchuli.php",        //处理页面        
 data:{u:uid},        //传递数据;前为名,后为值        
 type:"POST",    //数据提交方式        
 dataType:"TEXT",    //返回的数据类型        
 success:function(data){        //回调函数            
 if(data.trim()=="ok"){        //trim()去掉php文件前后空格                
 $("#test").text("该用户名可以使用!");                
 $("#test").css("color","green");            
 }else{                
 $("#test").text("用户名已存在!");                
 $("#test").css("color","red");            
 }        
 }   
 });
 }
 )
</script>
</html>

php processing page

<?php
$uid = $_POST["u"];
require_once "./DBDA.class.php";
$db = new DBDA();
$sql = "select count(*) from users where uid=&#39;{$uid}&#39;";
$arr = $db->query($sql,0);
if($arr[0][0]){//用户名存在
    echo "no";
}else{
    echo "ok";
}

The above is the detailed content of Basic operations related to AJAX. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn