|
 |
|
เราสามารถทำ if else ที่ส่ง get ตอนกดลิ้ง โดยไม่ให้หน้ามันรีเฟรชได้ป่าวครับ |
|
 |
|
|
 |
 |
|
Ajax ครับ
|
 |
 |
 |
 |
Date :
2019-01-30 08:13:33 |
By :
ilikeit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
test.php
Code (PHP)
<meta charset="utf8">
<!DOCTYPE html>
<html>
<body>
<h2>เปลี่ยนหน้าโดยไม่ รีเฟรช</h2>
<button type="button" onclick="loadDoc()">home</button>
<button type="button" onclick="loadDoc1()">page1</button>
<button type="button" onclick="loadDoc2()">page2</button>
<p id="demo">ข้อมูลตรงนี้จะถูกแทนที่ด้วย การดึงหน้า page อื่นๆ เข้ามา</p>
<script>
function loadDoc() {
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
//ไปสร้างหน้าเพิ่มเติม ใน folder ของเรา
xhttp.open("GET", "home.php", true);
xhttp.send();
}
function loadDoc1() {
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
//ไปสร้างหน้าเพิ่มเติม ใน folder ของเรา
xhttp.open("GET", "page1.php", true);
xhttp.send();
}
function loadDoc2() {
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
//ไปสร้างหน้าเพิ่มเติม ใน folder ของเรา
xhttp.open("GET", "page2.php", true);
xhttp.send();
}
</script>
</body>
</html>
ส่วนวิธีส่งค่า GET ไปด้วยก็หาเพิ่มดูครับ
ผมว่ามันน่าจะง่ายอยู่ครับ เลยไม่ทำเพิ่มให้
|
 |
 |
 |
 |
Date :
2019-01-30 09:38:17 |
By :
nobetaking |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่อยู่ครับ กลับไปยังจุดเริ่มต้น
เพราะมันเหมือน Template แค่ดึงหน้าอื่นมาแสดง
ถ้าต้องการแบบไม่ต้องรีเฟรส หน้าจริงๆ ให้ไปศึกษาพวกนี้ครับ
Laravel + VueJS
ใช่ดี คนที่เป็นโปรแกรมเมอร์มืออาชีพ บางคน จะใช้พวกนี้ครับ
|
 |
 |
 |
 |
Date :
2019-01-30 16:18:32 |
By :
nobetaking |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|