Link to home
Create AccountLog in
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;
                        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");

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.

User generated image
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.
Avatar of Zvonko
Flag of North Macedonia image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of -Dman100-


Thank you!! Yes, that worked. How did returning false fix the issue?
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:

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

Is this explanation enough for you?