|
|
|
อยากทราบการส่งค่าของuserที่login ข้ามหน้า ด้วยApi ajax |
|
|
|
|
|
|
|
<script>
$('#btnLogin').click(function () {
var txtUsername = $("#txtUsername").val();
var txtPassword = $("#txtPassword").val();
$.ajax({
url: 'http://localhost:5000/api/Home/Login',
type: 'POST',
dataType: 'JSON',
data: JSON.stringify({
txtUsername: txtUsername,
txtPassword: txtPassword
}),
contentType: 'application/json',
success: function (res) {
if (res.isCustomer == true) {
console.log("successaaaaaaaaaaa",res.isCustomer);
Swal.fire({
title: '<strong><u>Wellcome User </u></strong>',
icon: 'info',
html: res.message,
// html:
// '<p>Name : ' + res.nameEng + '</p>' +
// '<p>Position : ' + res.positionNameEng + '</p>' +
// '<p>Staff Level : ' + res.staffNameEng + '</p>' +
// '<p>Division : ' + res.divisionNameEng + '</p>',
confirmButtonText: '<i class="fas fa-user-check"></i> OK',
}).then((result) => {
if (result.value) {
window.location = "user_index.php";
}
})
}
else {
console.log("warning",res);
Swal.fire({
title: '<strong><u>Wellcome Technician </u></strong>',
icon: 'warning',
html: res.message,
confirmButtonText: '<i class="fas fa-skull-crossbones"></i> OK',
}).then((result) => {
if (result.value) {
window.location = "tech/index.php";
}
})
}
},
failure: function (res) {
Swal.fire({
title: '<strong><u>Error</u></strong>',
icon: 'error',
html: res.message,
confirmButtonText: '<i class="fas fa-skull-crossbones"></i> OK',
}).then((result) => {
if (result.value) {
window.location = "logintest.php";
}
})
},
});
});
</script>
จากสคิปหน้าLogin อยากทราบวิธีให้ข้อมูลข้อ user ที่Loginเข้ามา ส่งข้อมูลไปยังหน้าDashboardของuserคนนั้นๆด้วยครับ ตัวอย่าเช่นชื่อ Username เพื่อรุบะว่าเป็นใคร จะมีสคิปไหนที่สามารถรับค่าไปหน้าdashboardได้มั่งครับ
Tag : PHP, Ms SQL Server 2016, Ajax, jQuery
|
|
|
|
|
|
Date :
2020-12-16 01:19:39 |
By :
alphatize13 |
View :
580 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- จริงแล้วเขียนในลักษณะที่เขียนมา ควรเปลี่ยนจาก var เป็นพวก const,let เพื่อกันข้อมูลไหลออกนอก scope
- และก็ต้องถามอีกว่า เป็น Single page รึเปล่า ถ้าเป็น SPA ให้เก็บเป็น array ในรูปแบบ javascript
- แต่ถ้ามีการ Refresh ข้อมูลนั้นจะหายไป เราจำเป็นต้องเก็บค่าใน Browser โดยใช้ localStorage.setItem ในรูปแบบ Token เพื่อความปลอดภัย
- หรือไม่งั้นใช้ VueJS ทำ front end และใช้ Laravel ทำ back end โดยยิงค่า API Passport
|
|
|
|
|
Date :
2020-12-16 09:18:15 |
By :
Genesis™ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|