PageSourceSearch

http://xjro.com/js/landing.js

js xjro.com collected 2026-10-08 11:31:56 UTC 5,492 bytes, 148 lines download raw bytes

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.