Only jquery console.log statement is not working in AEM. Other lines of code executes well. Is there a way to debug this issue? | Community
Skip to main content
BinaryAlchemy11
Level 3
October 28, 2024

Only jquery console.log statement is not working in AEM. Other lines of code executes well. Is there a way to debug this issue?

  • October 28, 2024
  • 6 replies
  • 3969 views

Is there a way to debug the following code where the line for the console.log doesn't log the message "Test message" in console? But the next line alert("Test Alert") works fine.

 

$(document).ready(function() {

         console.log("Test message");

         alert("Test Alert");

});

 

One more thing to notice is in below code, "0000" is printed in output but not "99":

 

<script>
$(document).ready(function(){
          console.log("99");
});
console.log("0000");
</script>

 

I have tried changing the version of the jquery CDN link to the previous versions and am still facing the same issue.

Using this version of jquery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

6 replies

PRATHYUSHA_VP
Community Advisor
Community Advisor
October 28, 2024

Hi @binaryalchemy11 

 

The above code snippet should work as expected. If the jquery library is loaded console.log will print the statement. 

 

Try to debug from the developer console in chrome and check the statement is passing through. If there's any error please post the screenshot

 

Hope this helps

 

Thanks

 

BinaryAlchemy11
Level 3
October 29, 2024

Hi @prathyusha_vp ,

 

I have the jquery library loaded as well:

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

 

Also, have tried debug in developer console. It does go through the console.log line however it does't print the output in console.

 

Best Regards,

Anish

PRATHYUSHA_VP
Community Advisor
Community Advisor
October 30, 2024

As per above update in QnA where in you have observed 0000 is printed but not 99 ,

that means document is not ready when you're trying to print this statement. 

 

The .ready() method offers a way to run JavaScript code as soon as the page's Document Object Model (DOM) becomes safe to manipulate

 

<script>
$(document).ready(function(){
          console.log("99");
});
console.log("0000");
</script>

 

Please find relevant explanation over here, also try to display console when DOM is loaded, we can find root cause of it 

 

https://api.jquery.com/ready/

 

Hope this helps

 

Thanks

Level 4
October 28, 2024

Hi @binaryalchemy11 ,

as @prathyusha_vp mentioned below you shall try pudding a debug point in the browser console (F12) and debug your JS file, 

FYI -

 

Thanks,

Raju.

BinaryAlchemy11
Level 3
October 29, 2024

Yes I have tried doing so and the it goes through the line for console.log but doesn't print output.

 

-Anish

Tethich
Community Advisor
Community Advisor
October 28, 2024

Hi @binaryalchemy11 

 

There is a chance that somewhere in your code, maybe another clientlib, to have a line like the one below, that disables all console.log outputs:

 

console.log = function() {}

 

Worth checking this out as well.

BinaryAlchemy11
Level 3
October 29, 2024

@tethich:

I was thinking the same as well. Was thinking something might have disabled the console.log part on the site. However, I am unable to find any console.log = function() {} in the clientlibs used.

Is there any other js code that could have possible disabled the console.log?

 

-Anish

 

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
October 28, 2024

Hi, 

If you are using Chrome, make sure you have set it up to display all the log statements in the browser console. If this is a testing environment you can always add the "debugger;" statement to stop the execution of the JS and see what's going on with the console statement.

Hope this helps

Esteban Bustamante
BinaryAlchemy11
Level 3
October 29, 2024

Just checked and it is selected to display all logs. Have tried using debugger and the line right after it executes but not the console.log despite going through it.

 

-Anish

h_kataria
Community Advisor
Community Advisor
October 29, 2024

Hi @binaryalchemy11 
Could you check if "info" is unselected by any chance for log level in your developer console. It should be selected. 

 

 

BinaryAlchemy11
Level 3
October 29, 2024

This section for Default Levels is greyed out for me.

 

-Anish

h_kataria
Community Advisor
Community Advisor
November 4, 2024

Do you see any other errors on your console ? My assumption would be your code executes before your jquery is loaded on the page. 

kautuk_sahni
Community Manager
Community Manager
November 5, 2024

@binaryalchemy11 Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!

Kautuk Sahni
BinaryAlchemy11
Level 3
November 5, 2024

Hmm yes the suggestions are helpful but still not been able to resolve the issue.