Hiển thị các bài đăng có nhãn supplier-vietB2b. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn supplier-vietB2b. Hiển thị tất cả bài đăng

Thứ Tư, 2 tháng 9, 2026

Thiết lập get dữ liệu đuôi.php cùng Module PHP

 


Đang sử dụng file Edit_Supplier.php và gọi đến file upload.momento.php

**** JS

function uploadMomentoFile_<?php echo $uniqueId; ?>() {

        

    var form = document.getElementById('form_<?php echo $uniqueId; ?>');

    var formData = new FormData(form);

    var status = document.getElementById('status_<?php echo $uniqueId; ?>');

    var targetUrl = '<?php echo rtrim($site_live, "/"); ?>/modules.php?name=Shoping&file=upload_momento';

    status.textContent = "Đang lưu ảnh...";

    fetch(targetUrl, {

        method: 'POST',

        body: formData

    })

    .then(function(response) {

        return response.text(); // Lấy dữ liệu thô dạng text

    })

    .then(function(text) {

        // Tách lọc lấy phần chuỗi JSON chuẩn {...} phòng trường hợp bị dính HTML

        var jsonStart = text.indexOf('{');

        var jsonEnd = text.lastIndexOf('}') + 1;

        

        if (jsonStart !== -1 && jsonEnd !== -1) {

            var cleanJson = text.substring(jsonStart, jsonEnd);

            var data = JSON.parse(cleanJson);


            if (data.success) {

                status.textContent = "Lưu thành công: " + data.filename;

                loadPanorama_<?php echo $uniqueId; ?>(data.url + '?v=' + new Date().getTime());

            } else {

                alert('Lỗi: ' + data.message);

                status.textContent = "Lưu thất bại!";

            }

        } else {

            console.error("Dữ liệu server trả về không phải JSON:", text);

            alert("Lỗi server trả về dữ liệu không hợp lệ! Kiểm tra Console (F12)");

            status.textContent = "Lỗi phản hồi!";

        }

    })

    .catch(function(err) {

        console.error(err);

        alert('Lỗi kết nối máy chủ!');

        status.textContent = "Lỗi tải lên!";

    });

}