Magento 1.9 – Display Message in Popup Instead of Redirecting

magento-1.9popupproduct-view

once registered user click on button in view page we are creating new product and displaying that information in pop up as below

enter image description here

button code : [ full code : https://pastebin.com/da60SSWH ]

    <button  onclick="return setproductlogin(\'<?php echo 

Mage::registry("current_product")->getId()?>\', event);setrequestlogin();" 

  id="submit-editorApply-{{rand}}">save design</button>

image url script [ full code : https://pastebin.com/19K43TyR ]

saveImageDefaultUrl   : '<?php echo Mage::helper('aitcg')-

>getSecureUnsecureUrl(Mage::getUrl('aitcg/ajax/createImageDefault',array('id' =>

 Mage::registry("current_product")->getId()))); ?>',

but if guest click on same button, its creating new product , but its redirecting to another page , but we want to display that message in pop up…. [ controllers : https://pastebin.com/9wsgufJX ]

enter image description here

Best Answer

I think you will require to add jQuery for this. Try adding below jquery code in your login popup "Login into your Account 4"

Add below code after this line,

var ajaxLoginForm = new VarienForm('ajaxlogin-login-form', true);

jQuery("#ajaxlogin-login-form").submit(function(e) {
    e.preventDefault();
    if (ajaxLoginForm.validator.validate()) {
        jQuery.ajax({
            type: "POST",
            url: jQuery('#ajaxlogin-login-form').attr('action'),
        }).done(function(result) {
            alert(result);
        }).fail(function() {
            alert('There is some error saving your design.');
        });
    }
});
Related Topic