How can I stop JavaScript remoting reloading page

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












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();

Visualforce.remoting.Manager.invokeAction(
'!$RemoteAction.MyController.searchName'
,fieldContent
,function(result, event)
if (event.status)
if(result != null)
console.log('result');
console.log(result);
//do something

else

console.log('Here I am not');

else if (event.type === 'exception')
console.log('exception');
else
console.log('Beyond exception');


, escape: true
);

</script>


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










share|improve this question







New contributor




M. Massula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val();
    – Caspar Harmer
    1 hour ago

















up vote
2
down vote

favorite












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();

Visualforce.remoting.Manager.invokeAction(
'!$RemoteAction.MyController.searchName'
,fieldContent
,function(result, event)
if (event.status)
if(result != null)
console.log('result');
console.log(result);
//do something

else

console.log('Here I am not');

else if (event.type === 'exception')
console.log('exception');
else
console.log('Beyond exception');


, escape: true
);

</script>


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










share|improve this question







New contributor




M. Massula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val();
    – Caspar Harmer
    1 hour ago













up vote
2
down vote

favorite









up vote
2
down vote

favorite











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();

Visualforce.remoting.Manager.invokeAction(
'!$RemoteAction.MyController.searchName'
,fieldContent
,function(result, event)
if (event.status)
if(result != null)
console.log('result');
console.log(result);
//do something

else

console.log('Here I am not');

else if (event.type === 'exception')
console.log('exception');
else
console.log('Beyond exception');


, escape: true
);

</script>


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










share|improve this question







New contributor




M. Massula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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();

Visualforce.remoting.Manager.invokeAction(
'!$RemoteAction.MyController.searchName'
,fieldContent
,function(result, event)
if (event.status)
if(result != null)
console.log('result');
console.log(result);
//do something

else

console.log('Here I am not');

else if (event.type === 'exception')
console.log('exception');
else
console.log('Beyond exception');


, escape: true
);

</script>


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







apex visualforce javascript javascript-remoting remote-action






share|improve this question







New contributor




M. Massula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




M. Massula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




M. Massula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 hours ago









M. Massula

111




111




New contributor




M. Massula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





M. Massula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






M. Massula is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val();
    – Caspar Harmer
    1 hour ago

















  • you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val();
    – Caspar Harmer
    1 hour ago
















you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val();
– Caspar Harmer
1 hour ago





you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val();
– Caspar Harmer
1 hour ago











2 Answers
2






active

oldest

votes

















up vote
3
down vote













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.






share|improve this answer




















  • 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
    1 hour ago


















up vote
0
down vote













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






share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "459"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    M. Massula is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f237029%2fhow-can-i-stop-javascript-remoting-reloading-page%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    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.






    share|improve this answer




















    • 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
      1 hour ago















    up vote
    3
    down vote













    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.






    share|improve this answer




















    • 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
      1 hour ago













    up vote
    3
    down vote










    up vote
    3
    down vote









    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.






    share|improve this answer












    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 1 hour ago









    sfdcfox

    234k10180396




    234k10180396











    • 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
      1 hour ago

















    • 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
      1 hour ago
















    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
    1 hour ago





    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
    1 hour ago













    up vote
    0
    down vote













    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






    share|improve this answer


























      up vote
      0
      down vote













      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






      share|improve this answer
























        up vote
        0
        down vote










        up vote
        0
        down vote









        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






        share|improve this answer














        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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 32 mins ago

























        answered 38 mins ago









        Pranay Jaiswal

        9,51231949




        9,51231949




















            M. Massula is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            M. Massula is a new contributor. Be nice, and check out our Code of Conduct.












            M. Massula is a new contributor. Be nice, and check out our Code of Conduct.











            M. Massula is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f237029%2fhow-can-i-stop-javascript-remoting-reloading-page%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery