How can I stop JavaScript remoting reloading page
Clash 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
apex visualforce javascript javascript-remoting remote-action
New contributor
add a comment |Â
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
apex visualforce javascript javascript-remoting remote-action
New contributor
you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val();
â Caspar Harmer
1 hour ago
add a comment |Â
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
apex visualforce javascript javascript-remoting remote-action
New contributor
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
apex visualforce javascript javascript-remoting remote-action
New contributor
New contributor
New contributor
asked 2 hours ago
M. Massula
111
111
New contributor
New contributor
you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val();
â Caspar Harmer
1 hour ago
add a comment |Â
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
add a comment |Â
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.
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
add a comment |Â
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
add a comment |Â
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.
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
add a comment |Â
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.
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
add a comment |Â
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.
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.
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
edited 32 mins ago
answered 38 mins ago
Pranay Jaiswal
9,51231949
9,51231949
add a comment |Â
add a comment |Â
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.
M. Massula is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
you need to prevent default.-> function getRemoteName(event) { event.preventDefault(); var fieldContent = $('.elementClassId').val();
â Caspar Harmer
1 hour ago