Ajax表单提交在Safari 8.0.2中不起作用

时间:2015-01-20 00:14:34

标签: javascript jquery ajax magento safari

我有一个通过ajax提交的表单。它在我测试的每个浏览器上工作正常,在我的开发服务器上工作正常但在我的生产服务器上根本不起作用(我能想到的唯一区别是生产服务器使用的是https)。另外值得注意的是:这是针对Magento环境的,我删除了表单添加和删除速率的部分,因为它们看起来工作正常。抱歉这个长度。

这是HTML:

<form id="shipping-details" enctype="multipart/form-data" method="post">

<ol class="form-list" id="wk_bodymain">
    <li class="flat-rate">
        <div class="six columns alpha">
<h4>Add a Flat Rate</h4>
<p>A flat shipping rate is used as a default shipping rate to make sure you are covered in any situation you haven't defined within an individual rate listed below. So basically, it's used as a shipping rate backup just in case you forget to enter in a rate to cover a product that you have for sale.</p>

</div>
<div class="twelve columns omega">
    <div class="country-header">
            <img src="/skin/frontend/zb-2013/default/images/account-shipping-american-flag-icon.png" alt="United States Flag">
            <h4>Default Shipping Rate</h4>
        </div>

        <ul id="flat-rules">
                <li id="14">
            <span class="location">All States Flat Rate </span>
            <div class="peerice"><span class="price">$25.00</span></div>
            <span class="delete"><a href="#" onclick="deleteRule(14); return false;"><i class="icon-trash mp_delete"></i></a></span>    
        </li>
                </ul>
        </div>
    </li>
<li>


<div class="six columns alpha">
<h4>Additional Shipping Rates</h4>
<p>Add new shipping rates. Please note that we only allow shipping to the United States at this time. To designate all ZIP codes within a state, just use the * character (shift + 8) which means "all".</p>
<div class="medium metro btn default"><a href="#" class="add_btn"><i class="icon-plus-squared"></i>Add a rate</a></div>
</div>
<div class="twelve columns omega">
<div class="country-header">
    <img src="/skin/frontend/zb-2013/default/images/account-shipping-american-flag-icon.png" alt="United States Flag"/>
    <h4>United States</h4>
</div>
    <ul id="shipping-rules">
        <li id="7">
            <span style="display:none;">US</span>
            <span class="location">
                California          </span>
            <span class="zipCd">
                All ZIP Codes           </span>

            <span>0 - 13 lbs</span> 
            <div class="peerice"><span class="price">$1.50</span></div>
            <span class="delete"><a href="#" onclick="deleteRule(7); return false;"><i class="icon-trash mp_delete"></i></a></span> 
        </li>
                <li id="8">
            <span style="display:none;">US</span>
            <span class="location">
                Colorado            </span>
            <span class="zipCd">
                All ZIP Codes           </span>

            <span>0 - 14 lbs</span> 
            <div class="peerice"><span class="price">$15.66</span></div>
            <span class="delete"><a href="#" onclick="deleteRule(8); return false;"><i class="icon-trash mp_delete"></i></a></span> 
        </li>
                <li id="9">
            <span style="display:none;">US</span>
            <span class="location">
                Alabama         </span>
            <span class="zipCd">
                All ZIP Codes           </span>

            <span>0 - 12 lbs</span> 
            <div class="peerice"><span class="price">$6.00</span></div>
            <span class="delete"><a href="#" onclick="deleteRule(9); return false;"><i class="icon-trash mp_delete"></i></a></span> 
        </li>


        </ul>
</div>
</li>
</ol>
<ul id="add-rates">
</ul>
</form>
<div class="row bottomSave">
    <div class="buttons-set eight columns omega">
        <button type="submit" class="sub_btn">
            Save Shipping Rates     </button>
    </div>
</div>

和Javascript:

<script>
jQuery.noConflict();
function removeRule(position){
    jQuery("#add-rates li."+position).remove();
}



(function(){


var newCustomerProductForm = new VarienForm('shipping-details', true);
jQuery(document).on('click','.sub_btn',function(e){
        if(newCustomerProductForm.validator.validate()!==false){
            e.preventDefault();
            jQuery('.sub_btn').text('Saving...');
            jQuery('.sub_btn').parent('div.btn').addClass('disabled');
            jQuery('.sub_btn').css('cursor','default');
            jQuery('.sub_btn').attr('disabled','disabled');
            saveRules();
        }
});



var shippingDetails = [];
var position = 0;

function buildShippingDetails(){
    shippingDetails.length = 0;
    jQuery("#flat-rate li").each(function( index ) {
            var addArray = [];
            addArray[0] = jQuery(this).find( "input.dest_country_id" ).val();
            addArray[1]  = jQuery(this).find("input.dest_region_id").val();
            addArray[2]  = jQuery(this).find("input.dest_zip").val();
            addArray[3]  = jQuery(this).find("input.dest_zip_to").val();
            addArray[4]  = jQuery(this).find("input.weight_from").val();
            addArray[5]  = jQuery(this).find("input.weight_to").val();
            addArray[6]  = jQuery(this).find("input.price").val();
            addArray.toString();
            shippingDetails.push(addArray);

        });
    jQuery("#shipping-details ul li.content").each(function( index ) {
            var addArray = [];
            addArray[0] = jQuery(this).find( "input.dest_country_id" ).val();
            addArray[1]  = jQuery(this).find("select.dest_region_id option:selected").val();
            addArray[2]  = jQuery(this).find("input.dest_zip").val();
            addArray[3]  = jQuery(this).find("input.dest_zip_to").val();
            addArray[4]  = jQuery(this).find("input.weight_from").val();
            addArray[5]  = jQuery(this).find("input.weight_to").val();
            addArray[6]  = jQuery(this).find("input.price").val();
            addArray.toString();
            shippingDetails.push(addArray);

        });

    }


jQuery( "#shipping-details" ).on( "change", "input", function() { 
    buildShippingDetails();

});
jQuery( "#shipping-details" ).on( "change", "select", function() { 
    buildShippingDetails();

});

jQuery( ".col-main" ).on( "click", ".add_btn", function(e) { 
    e.preventDefault();
    position = addSection(position);

});


function saveRules(){
    var data = JSON.stringify(shippingDetails);
    var postUrl = 'https://www.zero-bars.com/mpshipping/shipping/save/';
    if (newCustomerProductForm.validator.validate()) {
            new Ajax.Updater(
                { success: window.location = "https://www.zero-bars.com/mpshippingmanager/shipping/" }, postUrl, {
                    method:'post',
                    parameters: {info: data},
                    onComplete:function(msg) {
                        window.location = "https://www.zero-bars.com/mpshippingmanager/shipping/";
                        //console.log("Form submit complete");
                    }

                }
            );
     } 
    }       
})(jQuery);
</script>   

0 个答案:

没有答案