1

I want to refresh the product page automatically if the user clicks on "CHECK" button of zipcode field. I want to refresh the page automatically every time user click on CHECK button of zipcode or want to refresh the add to cart button & zipcode section as i marked in attached screenshot. I am providing you the cod.phtml

cod.phtml

<?php
/***************************************
 *** Cash On Delivery ***
 **************************************
 */

$msgData = Mage::helper('netgo_cod')->getConfigData(); 
if($msgData['zip_status'] == 1){
?>
<div class="input-box">
    <div class="z-btn">
        <label>Zip Code : </label><input type="text" placeholder="Enter your pincode" value="" name="cod" class="product-custom-option required-entry" id="cod" size="29" style='color:black; font-size:12px'>
        <button type="button" onclick="checkCOD();" name="zip-check" title="Check" class="button" id="zip-check"><span><span>Check</span></span></button>
    </div>
    <div id="cod_msg"></div>
</div>

<script>
    function checkCOD(){
             var zipcode;
        var cod = $('cod').value;
        if(cod == ''){
            $('cod_msg').update('<span class="cod-error"><?php echo $msgData['emp_msg']; ?></span>');
            return
        }else{
            $('cod_msg').update('<img src="<?php echo Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB, true ).'media/cod/img/ajax-loader-2.gif';?>">'); 
            new Ajax.Request('<?php echo Mage::getBaseUrl().'netgo/cod/check';?>', {
                method:'post',
                parameters: {zipcode: cod}, 
                onSuccess: function(transport) {
                    var response = transport.responseText || "no response text";
                    $('cod_msg').update(response);

                    if(response.search('Delivery of the book is not available on the above pincode')!=-1)
                                        {
                                          zipcode='checked';
                                          jQuery('.btn-cart').attr('disabled', 'disabled'); 
                                        }
                                      else
                                      {
                                      zipcode='';

                                      }

                },
                onFailure: function() { alert('Something went wrong...'); }
            });
        }
    }
</script>
<?php } ?>

Screenshot:

enter image description here

1
  • any answer stackys Commented Oct 26, 2016 at 16:25

2 Answers 2

0
jQuery.ajax({
                type:"GET",
                url:location,
               success:function(data){
                       parent.window.location.href = "/checkout/cart/";
               }
        });

You can use something like this.

Here the parent.window.location.href is the main code which refresh the given page.

Not necessary you should ajax, but you can do it on simple function also,

it is just an example, you can modify it accordingly.

Hope it works for you, let me know the status after applying.

7
  • 1
    but in which part i used this code you provided, can u suggest me your code in the code that i provided cod.phtml Commented Oct 28, 2016 at 1:13
  • Yes sure. In your Ajax function, on success: tab add this line at the last line Commented Oct 28, 2016 at 4:11
  • parent.window.location.href = "/checkout/cart/"; add this line on last line of your success: tab in your Ajax function Commented Oct 28, 2016 at 4:12
  • So that after successfully fetching the result in Ajax, at last line it will surely refresh the page. Let me know your feedback. Commented Oct 28, 2016 at 4:13
  • Sorry for the late reply, I am checking now & update you within 2 min. Commented Oct 29, 2016 at 10:23
0

Take a look at the following code modify it as per your need hope that will help you.

I am not sure hot do you get the variable values, I made some update hope that will resolve your issue.

<div class="input-box">
    <div class="z-btn">
        <label>Zip Code : </label><input type="text" placeholder="Enter your pincode" value="" name="cod" class="product-custom-option required-entry" id="cod" size="29" style='color:black; font-size:12px'>
        <button type="button" onclick="checkCOD();" name="zip-check" title="Check" class="button" id="zip-check"><span><span>Check</span></span></button>
    </div>
    <div id="cod_msg"></div>
</div>

<script>
    function checkCOD(){
        var zipcode; // Don't know why you declare this variable
        var cod = jQuery('#cod').value;
        if(cod == ''){
            jQuery('#cod_msg').html('<span class="cod-error"><?php echo $msgData['emp_msg']; ?></span>');
            return;
        }else{
            $('#cod_msg').html('<img src="<?php echo Mage::getBaseUrl( Mage_Core_Model_Store::URL_TYPE_WEB, true ).'media/cod/img/ajax-loader-2.gif';?>">'); 

            jQuery.ajax({
                type: "POST",
                url: <?php echo Mage::getBaseUrl().'netgo/cod/check';?>,
                data: {zipcode: cod},
                success: function (data) {
                    if (!(typeof (data) === 'undefined')) {
                        if (data.find('Delivery of the book is not available on the above pincode')) {
                            jQuery('.btn-cart').attr('disabled', 'disabled'); 
                        } else {
                            zipcode=''; // Not Defined as per your code, do whatever you want to do
                            // Get the response from your code and assign that html to where ever you want.
                            // Write your controller action to send and html response so that you can directly 
                            //put that html here and assign to any div.
                        }
                    }
                },
                error: function(xhr, textStatus, errorThrown){
                   alert('Something went wrong...');
                }
            });
        }
    }
</script>
3
  • 1
    Your code does work ashish Commented Oct 28, 2016 at 1:11
  • Any answer stacky's Commented Oct 29, 2016 at 10:36
  • Any answer stacky's Commented Oct 30, 2016 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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