Ivonne Aspilcueta

Ivonne Aspilcueta

  • 882
  • 622
  • 10.2k

Uncaught (in promise) Error: JavaScript

Oct 18 2024 5:30 PM

Hello,

Can someone give any ideas why this is happening, I've had many days reseraching and changing the code as suggested but it is not working; I received the following error:

“Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received”

Doing some research on, I found out that maybe is a cross-origin request issue and it is caused by various Chrome Extensions, but I checked and I do not have any Chrome extension blocking.

Thank you.

async function getUserDetails(MemberID) {
    try {
        const config = {
           
            server: '.',
            database: 'WebForms',
            options: {
                //encrypt: true // Use this if you're on Azure
            }
        };

        // Connect to the database
        await sql.connect(config);

        // Query the database
        const result = await sql.query`SELECT RTRIM(LTRIM(CONCAT(COALESCE(FirstName + ' ', ''), COALESCE(LastName, '')))) AS MemberName, SSN FROM dbo.Members WHERE MemberID = ${MemberID}`;
        
        if (result.recordset.length > 0) {
          const { MemberName, SSN } = result.recordset[0];

          console.log(`Name: ${MemberName}, SSN: ${SSN}`);

          document.getElementById("membername").value = MemberName;                                        
          document.getElementById("SSN").value = SSN;
  
          
                                                                         
          } else {
              console.log('No user found with the provided account number.');
  
              document.getElementById("membername").value = '';                                          
              document.getElementById("SSN").value = '';
          }
          
          
                                           
    } catch (err) {
        console.error('SQL error', err);
    } finally {
        await sql.close();
    }                                    
}

 


Answers (3)