chuyen thiet ke web
chuyen thiet ke web
chuyen thiet ke web
chuyen thiet ke web
chuyen thiet ke web

PHP#32MySQL#28 - Ajax3 + EMAIL

//connect.php

<?php
$link=@mysqli_connect("localhost","root","") or die("Khong the ket noi den server");
mysqli_select_db($link,"webtintuc") or die ("Kiem tra lai ten database!");
mysqli_query($link,"set names 'utf8'");
?>

//dangky.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="xuly_dangky.php">
  <p>
    <label for="hoten">Họ tên:</label>
    <input type="text" name="hoten" id="hoten">
  </p>
  <p>
    <label for="diachi">Dia chi:</label>
    <input type="text" name="diachi" id="diachi">
  </p>
  <p>
    <label for="username">Username:</label>
    <input type="text" name="username" id="username">
  </p>
  <p>
    <label for="pass">Password:</label>
    <input type="text" name="pass" id="pass">
  </p>
  <p>
    <label for="email">Email:</label>
    <input type="text" name="email" id="email">
  </p>
  <p>
    <input type="submit" name="dangky" id="dangky" value="Đăng ký">
  </p>
</form>
</body>
</html>

PHP#31MySQL#27 - Ajax2

//checkuser.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-3.6.0.js"></script>
</head>

<body>
<script type="text/javascript"> 
$(document).ready(function(){
$("#username").blur(function(){
$.ajax({
                    type:"POST",
                    url:"xuly_checkuser.php",
                    data:"user="+$("#username").val(),
                    success:function(abc)
{
                        if(abc=="1")
$("#kq").html("User này đã tồn tại. Mời bạn chọn user khác!");
else
{
$("#kq").html("User này chưa có. Bạn có thể sử dụng");
$("#dangky").removeAttr("disabled");
}
                    }
})
})
//Viết code cho sự kiện focus lên username:
$("#username").focus(function(){
$("#dangky").attr("disabled",true);
$("#kq").html("");
})
    });
</script>

<form method="get" id="form1" name="form1" action="">
  <p>
    <label for="textfield">Họ Tên:</label>
    <input type="text" name="hoten" id="hoten">
  </p>
  <p>
    <label for="username">Username:</label>
    <input type="text" name="username" id="username"><br/>
    <div id="kq"></div>
  </p>
  <p>
    <label for="password">Password:</label>
    <input type="password" name="password" id="password">
  </p>
  <p>
    <label for="confirmpassword">Re Password:</label>
    <input type="password" name="confirmpassword" id="confirmpassword">
  </p>
  <p>
    <input type="submit" name="dangky" id="dangky" value="Đăng ký" disabled>
  </p>
</form>
</body>
</html>

//xuly_checkuser.php

<?php 
if(isset($_POST['user']))
{
include("connect.php");
$user=$_POST['user'];
$sl="select * from webtm_user where Username='$user'";
$kq=mysqli_query($link,$sl);
if(mysqli_num_rows($kq))
echo "1";
else
echo "0";
}
?>

PHP#30MySQL#26 - Ajax

THAM KHẢO JQUERY

THAM KHẢO JQUERY

SELECTORS : Các cách chọn phần tử

  1. Chọn phần tử theo id

$("#vn").css("width","250px").css("border","solid 1px  #FF9933");

  1. Chọn phần tử theo tag

$("body").css("margin","20px");

  1. Chọn theo class

$(".mien").hide().slideDown(2000);

  1. Chọn phần tử có thuộc tính chứa chữ…

$("[href*='tintuc']").css("font-size","28px").css("text-transform","uppercase");

$("[href*='dulich']").css("font-style","italic");

  1. Chọn phần tử mà thuộc tính chứa chữ …

$("[href~='tuc']").css("padding-left","50px");

  1. Chọn phần tử có thuộc tính bắt đầu bằng …

$("[href^='tin']").css("color","#00CCFF");

  1. Chọn phần tử có thuộc tính kết thúc bằng …

$("[href$='/']").css("background-color","#660033");

  1. Chọn phần tử có thuộc tính khác với 1 giá trị 

$("a[href!='#']").css("text-decoration","underline");

  1. Chọn phần tử mà text có chứa chữ …

$("span:contains('t')").css("background-color","#003366"); 

  1. Chọn các phần tử có index lớn hơn …

$(".tinh:gt(2)").css("color","#CC0066");

  1. Chọn các phần tử có index nhỏ hơn …

$(".tinh:lt(2)").css("color","#660099");

  1. Chọn các phần tử có index bằng…

$(".tinh:eq(2)").css("color","#CCCC33");

  1. Chọn phần tử sau chót

$(".mien:last ul").append("<li>Hậu giang</li>");

  1. Chọn phần tử đầu tiên

$(".mien:first ul").prepend("<li>Tuyên quang</li>");

  1. Chọn các phần tử chẵn

$("#vn ul:even li:even").append(".");

  1. Chọn các phần tử lẻ

$("#vn ul:odd li:odd").append("...");

  1. Chọn phần tử con thứ n

$("#vn ul li:nth-child(2)").css("text-decoration","line-through");

  1. Chọn phần tử chỉ có 1 con

$("#vn li:only-child").css("border","solid 1px #FF3300"); //chọn chỉ 1 con



TRAVERSING

  1. Hàm .children() : Lấy các con của phần tử 

$("#menu").children().css("margin-bottom","5px"); 


$("#menu div").children(".loaitin").css("border","solid 1px #600");

  1. Hàm .find() : Tìm phần tử con 

$("#menu").find("[href]").css("text-transform","uppercase"); 

  1. Hàm  .first() Lấy phần tử đầu tiên trong tập hợp

  2. Hàm .last() Lấy phần tử cuối của tập hợp

  3. Hàm  .eq(): Lấy ra phần tử ở 1 chỉ số nào đó  trong  tập hợp

$(".loaitin").eq(2).css("font-size","30px");

  1. Thuộc tính .length : Số phần tử của tập hợp

alert($(".loaitin").length);

  1. Hàm .filter(): Lấy ra các phần tử thoã điều kiện 

$("div").filter(".loaitin").css("text-align","right");

$("a").filter(":even").css("text-align","center");

$("a").filter(":odd").css("text-align","right");

  1. Hàm .has(): Lấp phần tử có chứa một phần tử

$("a").has("span").css("font-style","italic");

  1. Hàm .is() : Kiểm tra phần tử hiện hành có phải là…

$('#menu').mouseover(function(event) {

  if ($(event.target).is('a') ) {

$(event.target).addClass('tosang');

  }

});

$('#menu').mouseout(function(event) {

  if ($(event.target).is('a') ) {

$(event.target).removeClass('tosang');

  }

});

  1. Hàm next : Lấy phần tử kế 

str = $("[idTL=2]").next().html();

alert(str);

  1. Hàm  .nextAll()  Lấy tất cả phần tử kế (sau nó) 

$("[idTL=2]").nextAll().css("font-weight","bold");

  1. Hàm  .nextUntil(): lấy các phần tử kế cho đến khi …

$("#tt").nextUntil("#sk").css("font-size","30px");

$("#tool").nextUntil("div").css("font-size","8px");

  1. Hàm .not(): Bỏ qua phần tử thõa điều kiện

$("a").not("[id='tt']").css("color","#66FF99");

  1. Hàm .parent():  Lấy phần tử cha

v = $("#tool").parent().parent().attr("idTL");

alert(v);

  1. Hàm .parents(): Lấy các đối tượng cha (đếm tận cùng bên ngoài)

$("#tool").parents().each(function(){  

t = $(this).attr('id') ; 

alert(t);

});

  1. Hàm   .each() : Lặp thông qua từng phần tử của tập hợp

  2. Hàm .parentsUntil(): Lấy đối tượng cha cho đến khi …

$("#tool").parentsUntil('body').each(function(){  

t = $(this).attr('id') ; 

alert(t);

});


$("#tool").parentsUntil('#bodycuatrang').each(function(){  

t = $(this).attr('id') ; 

alert(t);

});

  1. Hàm .prev(): Lấy đối tượng ở trước (láng giềng)

$("[idLT=5]").prev().html("Giải trí");

  1. Hàm .prevAll(): Lấy các đối tượng ở trước (láng giềng)

$("[idLT=5]").prevAll().css("padding-left","40px");

  1. Hàm .prevUntil(): Lấy các đối tượng ở trước (láng giềng) cho đến khi…

$("[idLT=5]").prevUntil('#tt').css("padding-left","40px");

  1. Hàm .siblings(): Lấy các đối tượng láng giềng (ở trước hoặc sau) 

$("[idLT=5]").siblings().css("padding-left","40px");

  1. Hàm .slice(): Lấy ra 1 tập hợp các phần tử theo chỉ số

$("[idTL=1] a").slice(1).css("text-align","right");

$("[idTL=1] a").slice(1,4).css("text-align","right");


MANIPULATION

  1. Hàm .css() : Định dạng CSS

  2. Hàm .attr() : set/get giá trị cho 1 thuộc tính html

tt = $("#test p:last").attr("thutu"); alert(tt);

  1. Hàm .html() : set/get mã html trong đối tượng

h = $("#test").html(); alert(h);

$("#test").html("<p>Loài bướm biết tìm thuốc để chữa bệnh</p>");

  1. Hàm .text() : set/get chữ trong đối tượng

t = $("#test").text(); alert(t);

  1. Hàm .val(): lấy giá trị của 1 đối tượng trong form

v = $("#lang").val(); alert(v);

v = $("#TenTL").val(); alert(v);

  1. Hàm .height():Độ cao của  đối tượng

cao = $("#test").height();

alert(cao);

  1. Hàm .width(): Độ rộng của đối tượng

rong=  $("#test p span:first").width();

alert(rong);

  1. Hàm .addClass(): Thêm class cho phần tử

$("#test").addClass('abc');

  1. Hàm .removeClass() : Gỡ bỏ class 

$("#test").removeClass("tosang");

  1. Hàm . after(): Thêm code html sau phần tử

$("#test p:last").after("<p>Hành trình kỳ lạ của cua đỏ</p>");

  1. Hàm .before(): Thêm code html trước phần tử

$("#test p:last").before("<p>Hành trình kỳ lạ của cua đỏ</p>");

  1. Hàm .append() : thêm html vào cuối đối tượng (bên trong)

$("#test p:last").append(" chúng ta");

  1. Hàm .prepend() : thêm html vào đầu đối tượng

$("#test p:last").prepend("Hình ảnh ");

  1. Hàm .appendTo(): Thêm mã html vào cuối đối tượng (bên trong)

$("<p>Loài ếch nhỏ bằng hạt đậu</p>").appendTo("#test");

  1. Hàm .detach(): Xóa phần tử

  2. Hàm .remove(): Xóa phần tử

  3. Hàm .empty(): Xóa phần tử

$("#test p:first").detach();

$("#test p:first").remove();

$("#test p:first").empty();

  1. Hàm .hasClass()

if( $("#test").hasClass("tosang")==true) alert("OK") ;

else alert("not OK");

  1. Hàm .offset(): Vị trí của phần tử trong trang web

L = $("#test").offset().left;

T = $("#test").offset().top;

alert(L +" " + T);

  1. Hàm .removeAttr(): Gõ bỏ 1 thuộc tính

  2. Hàm .scrollLeft()

  3. Hàm .scrollTop()

T = $("#footer").offset().top;

$(window).scrollTop(T);


$("#demo").scrollTop(100);

AJAX

  1. Hàm $.ajax(): Tạo request ajax, có thể chỉ định nhiều tham số (cache, data type, method…)

  2. Hàm  .load(): Tạo request ajax dạng get

  3. Hàm  $.get(): Tạo request ajax dạng get

  4. Hàm  $.post(): Tạo request ajax dạng post

  5. Hàm .serialize(): Lấy các giá trị trong form tạo thành chuỗi theo kiểu key1=value1&key2=value2…