1// landing.js - Fixed version 2// API URL - tá»± Äá»ng detect môi trưá»ng const API_BASE_URL = 'http://localhost:3001'; 3 4// API URL - Sá» dụng relative path vì Äã có reverse proxy 5// IIS sẽ tá»± Äá»ng forward request Äến backend 6const API_BASE_URL = ''; 7 8function showPopup(title, message, isSuccess) { 9 const popup = document.getElementById('simplePopup'); 10 const icon = document.getElementById('popupIcon'); 11 const svg = document.getElementById('popupSvg'); 12 13 document.getElementById('popupTitle').textContent = title; 14 document.getElementById('popupMessage').textContent = message; 15 16 if (isSuccess) { 17 icon.className = 'popup-icon success'; 18 svg.innerHTML = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M5 13l4 4L19 7" />'; 19 } else { 20 icon.className = 'popup-icon error'; 21 svg.innerHTML = '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M6 18L18 6M6 6l12 12" />'; 22 } 23 24 popup.classList.add('show'); 25} 26 27function closePopup() { 28 document.getElementById('simplePopup').classList.remove('show'); 29} 30 31// Close on overlay click 32document.getElementById('simplePopup')?.addEventListener('click', function (e) { 33 if (e.target === this) { 34 closePopup(); 35 } 36}); 37 38window.Register = { 39 getData: function () { 40 return { 41 FullName: document.getElementById("txtName")?.value.trim() || "", 42 PhoneNumber: document.getElementById("txtPhone")?.value.trim() || "", 43 Email: document.getElementById("txtEmail")?.value.trim() || "", 44 OccupationName: document.getElementById("ddlOccupation")?.value || "", 45 Address: document.getElementById("txtAddress")?.value.trim() || "", 46 Message: document.getElementById("txtMessage")?.value.trim() || "" 47 }; 48 }, 49 50 validate: function (d) { 51 if (!d.FullName) return "Vui lòng nháºp há» và tên"; 52 if (!/^0\d{9,10}$/.test(d.PhoneNumber)) return "Chưa nháºp sá» Äiá»n thoại hoặc sá» Äiá»n thoại không hợp lá»"; 53 if (d.Email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(d.Email)) return "Email không hợp lá»";
54 if (!d.OccupationName) return "Vui lòng chá»n Loại hình kinh doanh"; 55 if (!d.Address) return "Vui lòng nháºp Äá»a chá»"; 56 return ""; 57 }, 58 59 SendRegister: async function () { 60 var data = this.getData(); 61 var error = this.validate(data); 62 63 if (error) { 64 showPopup("Lá»i!!!", error, false); 65 return; 66 } 67 68 var submitBtn = document.querySelector(".submit-button"); 69 if (!submitBtn) { 70 console.error("Không tìm thấy nút submit"); 71 return; 72 } 73 74 var originalHTML = submitBtn.innerHTML; 75 submitBtn.disabled = true; 76 submitBtn.innerHTML = 'ÄANG GỬI...'; 77 78 try { 79 // Gá»i API bằng fetch 80 const url = `${API_BASE_URL}/Home/Save_Register`; 81 console.log('ð¤ Äang gá»i request Äến:', url); 82 console.log('ð¦ Dữ liá»u:', data); 83 84 const response = await fetch(url, { 85 method: 'POST', 86 headers: { 87 'Content-Type': 'application/json', 88 }, 89 body: JSON.stringify(data) 90 }); 91 92 if (!response.ok) { 93 throw new Error(`HTTP error! status: ${response.status}`); 94 } 95 96 const result = await response.json(); 97 console.log('ð¥ Nháºn response:', result); 98 99 if (result.ResponseCode > 0) { 100 // Reset form 101 document.getElementById("txtName").value = ""; 102 document.getElementById("txtPhone").value = ""; 103 document.getElementById("txtEmail").value = ""; 104 document.getElementById("ddlOccupation").value = ""; 105 document.getElementById("txtAddress").value = ""; 106 if (document.getElementById("txtMessage")) { 107 document.getElementById("txtMessage").value = ""; 108 } 109 110 showPopup( 111 "Gá»i thông tin thà nh công", 112 "Chá» GBE POS liên há» và há» trợ bạn nhé!", 113 true 114 ); 115 } else { 116 showPopup( 117 "Gá»i thông tin thất bại", 118 result.Description || "Vui lòng thá» lại sau", 119 false 120 ); 121 } 122 } catch (error) { 123 console.error('â Lá»i khi gá»i:', error); 124 showPopup( 125 "Gá»i thông tin thất bại", 126 "Không thá» kết ná»i Äến server. Vui lòng kiá»m tra kết ná»i mạng.", 127 false 128 ); 129 } finally { 130 submitBtn.disabled = false; 131 submitBtn.innerHTML = originalHTML; 132 } 133 } 134}; 135 136// Gắn sá»± kiá»n submit cho form 137document.addEventListener('DOMContentLoaded', function() { 138 const contactForm = document.getElementById("contactForm"); 139 if (contactForm) { 140 contactForm.addEventListener("submit", function (e) { 141 e.preventDefault(); 142 Register.SendRegister(); 143 }); 144 console.log('â Form Äã ÄÆ°á»£c khá»i tạo'); 145 } else { 146 console.error('â Không tìm thấy form vá»i id="contactForm"'); 147 } 148});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.