Avatar of -Dman100-
-Dman100-
Flag for United States of America asked on

How to debug AjaxRequest POST failure

I am working with communities in a Salesforce org. I have a page that does a search for files using a commandLink with a param. Upon button click of the icon for the commandLink a controller method is called and returns the appropriate result based on the search string from the inputText. This all works correctly.

However, if I search using the exact same search string and hit the enter key, the POST fails and I do not get a response. I have a JS script that fires onKeyPress and checks for the enter key code. The script fires and gets to the point of calling the controller method and then  nothing...

here is the script:

            <script type="text/javascript">
                function handleKeyPress(e){
                    var key = 0;
                    if(window.event){
                        key = e.keyCode;
                    }else if(e.which){
                        key = e.which;
                    }
                    if(key == 13){
                        console.log("We are about to call to call the controller method");
                        findFileMethod();                                         
                    }
                }
            </script>

Open in new window


I'm debugging in Firebug trying to identify the issue. Here is the POST failure that I'm seeing in the console window.

screenshot
There doesn't appear to be any JS error and it never reaches the controller method, so I'm stuck on how to debug this and see what the issue is.

Any help is appreciated.
AJAXWeb DevelopmentJavaScript

Avatar of undefined
Last Comment
Zvonko

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Zvonko

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
-Dman100-

ASKER
Thank you!! Yes, that worked. How did returning false fix the issue?
Zvonko

Your function handleKeyPress() works as an Event Handler and is able to do control over event preventDefault behaviour.
One of the ways to preventDefault is to return false from the Event Handler:
https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-cancelation

In your case the Enter key initiated the Form submission and that stopped the Ajax flow.

Is this explanation enough for you?
Your help has saved me hundreds of hours of internet surfing.
fblack61