0

MVC3 と Jquerymobile を使用したモバイル アプリケーションがあります。フォーム送信時(ajax機能あり)送信時とリダイレクト時に読み込みアイコン(ajax-loader.png)を表示したい。ありがとう!

私のajax関数:

 $("#add").click(function () {
    $.validator.unobtrusive.parse($('form'));  //added
    if ($("form").valid()) {
        var IDs = new Array($("#SelectedProduct").val(), $("#SelectedAccount").val(), $("#SelectedProject").val(), $("#SelectedTask").val(), $("#date").val(), $("#duration").val());
        $.ajax({
            url: '@Url.Action("SaveLine", "AddLine")',
            type: 'post',
            data: { ids: IDs },
            dataType: 'json',
            traditional: true,
            success: function (data) {
                if (data.success == true) {
                    $("#ajaxPostMessage").html(data.Success);
                    $("#ajaxPostMessage").addClass('ajaxMessage').slideDown(function () {
                        window.location.href = '@Url.Action("Index", "AddLine")';
                    }).delay(1800)
                }
                else {
                    $("#ajaxPostMessage").html(data.Error);
                    $("#ajaxPostMessage").addClass('ajaxMessage');
                    $("#ajaxPostMessage").show();
                }
            }
        });
    }
    return false;
});
4

1 に答える 1

0

試してください(未テスト):

$("#add").click(function () {
    $.validator.unobtrusive.parse($('form'));  //added
    if ($("form").valid()) {
        var IDs = new Array($("#SelectedProduct").val(), $("#SelectedAccount").val(), $("#SelectedProject").val(), $("#SelectedTask").val(), $("#date").val(), $("#duration").val());
        $.ajax({
            url: '@Url.Action("SaveLine", "AddLine")',
            type: 'post',
            data: { ids: IDs },
            dataType: 'json',
            traditional: true,
            beforeSend: function(jqXHR, settings){
                $.mobile.showPageLoadingMsg();
            },
            success: function (data) {
                $.mobile.hidePageLoadingMsg();
                if (data.success == true) {
                    $("#ajaxPostMessage").html(data.Success);
                    $("#ajaxPostMessage").addClass('ajaxMessage').slideDown(function () {
                        window.location.href = '@Url.Action("Index", "AddLine")';
                    }).delay(1800)
                }
                else {
                    $("#ajaxPostMessage").html(data.Error);
                    $("#ajaxPostMessage").addClass('ajaxMessage');
                    $("#ajaxPostMessage").show();
                }
            }
        });
    }
    return false;
});

ソース:

http://forum.jquery.com/topic/how-to-show-hide-loading-spinner-in-jquery-mobile http://api.jquery.com/jQuery.ajax/

于 2012-09-20T16:37:28.570 に答える