I'm trying to see what is my RemoteAction result however the page reloads before it happens.

How can I stop this?

VF Page:

<button class="btn-enter-panel" onclick="getRemoteName()">enter <i class="fa fa-long-arrow-right"></i></button>

JS Code:

<script type="text/javascript">
    function getRemoteName() {
        var fieldContent = $('.elementClassId').val();

            ,function(result, event){
                if (event.status) {
                    if(result != null){
                        //do something
                        console.log('Here I am not');
                } else if (event.type === 'exception') {
                } else {
                    console.log('Beyond exception');
            , {escape: true}

I've tried to follow this link JavaScript remoting reloading page but did't fit to my problem or I missunderstand how to apply in my case

  • you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val(); Oct 23, 2018 at 18:29

2 Answers 2


By default, a button will cause a form submit. You have to prevent this default either by cancelling the default behavior, or by returning "false" from your handler. The easiest method is to simply do this:

<button onclick="getRemoteName(); return false;" ...

This will prevent the default behavior from happening, and your function should be called.

  • Thanks @sfdcfox That worked, I tried to use event.preventDefault(); before, but that was inside my getRemoteName function, so did't work, now makes sence
    – M. Massula
    Oct 23, 2018 at 19:06

The page is reloading because browser is interpreting it as submit button. Default behaviour of submit button is to refresh. You can use the answer suggested by sfdcfox or can try the following:

You can make the type attribute of your button as "button". Some browsers act like submit if type is not specified.

<button class="btn-enter-panel" onclick="getRemoteName()" type="button">enter <i class="fa fa-long-arrow-right"></i></button>

Always specify the type attribute for a element. Different browsers use different default types for the element.

Src: https://www.w3schools.com/tags/tag_button.asp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.