Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
830 views
in Technique[技术] by (71.8m points)

jquery - ajax not working on ipad

I have a form:

<form id="orderForm" onsubmit="return prepareOrder(this);" action='@ConfigurationManager.AppSettings["EpayLogonUrl"]' method="POST">
         <input type="hidden" name="Signed_Order_B64" value="">
         <input type="hidden" name="email" size="50" maxlength="50" value="@Model.Email">
         <input type="hidden" name="appendix" value="@Model.AppendixInfo">
         <button class="wiz_button" type="submit" disabled="disabled">
         <span><span id="buy_button_name">Buy</span></span></button>
</form>

and a function PrepareOrder

function prepareOrder(form) {
    var selectedPayWay = $('.pay_cont.selected').data('way');
    var result;
    $.ajax({
        type: 'POST',
        url: '/Pay/CreateOrder',
        data: { payWay: selectedPayWay },
        success: function (response) {
            if (response.IsSuccess) {
                switch (selectedPayWay) {
                    case payWay.Terminal:
                        showBookingInfo(response.BookingId, response.ExpiredDate);
                        result = false;
                        break;
                    case payWay.Epay:
                        $("input[type=hidden][name=Signed_Order_B64]").val(response.SignedString);
                        $("input[type=hidden][name=appendix]").val(response.AppendixString);
                        result = true;
                        break;
                }

            } else {
                toastr.options.timeOut = 10000;
                toastr.info(response.Message);
                result = false;
            }
        },
        error: function () {
            result = false;
        },
        async: false
    });

    return result;
}

The problem is that on a new ipad (Safari) CreateOrder action is not called. On the desktop browser, it works fine. There are no errors in console. I tried to add an alert after:

success: function (response) {

like that:

success: function (response) {
alert(response.IsSuccess)

and alert return me true. Why? if CreateOrder is not called. I also added logging to CreateOrder action and there are no output strings.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Safari and/or Ipad support a very strong caching. I had the same problem in my application, too. Try adding following attributes to your controller (or even base controller):

[OutputCache(NoStore = true, Duration = 0)]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...