How to display success message after ajax form summit
I've been working on this code I found somewhere. I use it to submit the Send to Friend form from a popup. It works but I can't get it to display the success message after it submits the form. Right now after it submits the form it just disappears. Maybe someone good at ajax can see what's the matter with it. Thanks
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
magento-1.9 ajax forms
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I've been working on this code I found somewhere. I use it to submit the Send to Friend form from a popup. It works but I can't get it to display the success message after it submits the form. Right now after it submits the form it just disappears. Maybe someone good at ajax can see what's the matter with it. Thanks
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
magento-1.9 ajax forms
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I've been working on this code I found somewhere. I use it to submit the Send to Friend form from a popup. It works but I can't get it to display the success message after it submits the form. Right now after it submits the form it just disappears. Maybe someone good at ajax can see what's the matter with it. Thanks
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
magento-1.9 ajax forms
I've been working on this code I found somewhere. I use it to submit the Send to Friend form from a popup. It works but I can't get it to display the success message after it submits the form. Right now after it submits the form it just disappears. Maybe someone good at ajax can see what's the matter with it. Thanks
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
magento-1.9 ajax forms
magento-1.9 ajax forms
asked Apr 13 '16 at 15:57
FreejoyFreejoy
444924
444924
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess');
to Element.show('formSuccess2');
and added the div like this <div id="formSuccess2" style="display:none">hello</div>
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess2');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
add a comment |
Change code
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
}
to:
onComplete:function(request, json) {
$('formSuccess').show();
}
It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks
– Freejoy
Apr 13 '16 at 18:48
updated answer check it
– Prashant Valanda
Apr 13 '16 at 20:07
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f110781%2fhow-to-display-success-message-after-ajax-form-summit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess');
to Element.show('formSuccess2');
and added the div like this <div id="formSuccess2" style="display:none">hello</div>
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess2');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
add a comment |
Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess');
to Element.show('formSuccess2');
and added the div like this <div id="formSuccess2" style="display:none">hello</div>
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess2');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
add a comment |
Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess');
to Element.show('formSuccess2');
and added the div like this <div id="formSuccess2" style="display:none">hello</div>
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess2');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess');
to Element.show('formSuccess2');
and added the div like this <div id="formSuccess2" style="display:none">hello</div>
<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess2');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}
new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>
answered Apr 13 '16 at 19:21
FreejoyFreejoy
444924
444924
add a comment |
add a comment |
Change code
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
}
to:
onComplete:function(request, json) {
$('formSuccess').show();
}
It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks
– Freejoy
Apr 13 '16 at 18:48
updated answer check it
– Prashant Valanda
Apr 13 '16 at 20:07
add a comment |
Change code
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
}
to:
onComplete:function(request, json) {
$('formSuccess').show();
}
It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks
– Freejoy
Apr 13 '16 at 18:48
updated answer check it
– Prashant Valanda
Apr 13 '16 at 20:07
add a comment |
Change code
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
}
to:
onComplete:function(request, json) {
$('formSuccess').show();
}
Change code
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
}
to:
onComplete:function(request, json) {
$('formSuccess').show();
}
edited Apr 13 '16 at 20:07
answered Apr 13 '16 at 17:58
Prashant ValandaPrashant Valanda
9,55412353
9,55412353
It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks
– Freejoy
Apr 13 '16 at 18:48
updated answer check it
– Prashant Valanda
Apr 13 '16 at 20:07
add a comment |
It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks
– Freejoy
Apr 13 '16 at 18:48
updated answer check it
– Prashant Valanda
Apr 13 '16 at 20:07
It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks
– Freejoy
Apr 13 '16 at 18:48
It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks
– Freejoy
Apr 13 '16 at 18:48
updated answer check it
– Prashant Valanda
Apr 13 '16 at 20:07
updated answer check it
– Prashant Valanda
Apr 13 '16 at 20:07
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f110781%2fhow-to-display-success-message-after-ajax-form-summit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown