0

ページで何らかのアクションが呼び出されると、サーバー上の 2 つの異なるメソッドに対して 2 つの ajax 呼び出し (A、B) を行います。ほとんどの場合、各リクエストは一致するレスポンスを取得しますが、場合によっては両方のリクエストが同じレスポンスを取得します! (要求の 1 つ - A、A または B、B)

Ajax 呼び出しは JQuery を使用して行われ、サーバー メソッドは Play! を使用して実装されます。フレームワーク (Java)。

なぜそれが起こるのか、そしてそれを解決する方法を知っている人はいますか?

ありがとう!

Ajax コール A:

var renderTypePreviewPageRoute = jsRoutes.com.eyeview.connectad.controllers.solutions.FeedLibrary.getFeedTypePreviewPage(feedHashId, feedType);

    // Makes an ajax call that gets the rendered solution page
    $.ajax({

        // Sets the route (URL) of the server call
        url:renderTypePreviewPageRoute.url,

        // Sets the method (GET / POST) of the server call
        type:renderTypePreviewPageRoute.method,

        //data:{ hashId: feedHashId, feedType: feedType, withPreview: withPreview }-->

        // In case of success
        success:function(result) {

            var typePreviewElement = $('#typePreviewSection');

            // Set the feed preview section html content to the rendered content got from the server
            typePreviewElement.html(result);

            typePreviewElement.removeClass('hidden');

            $('#feedPreviewGrid tr:eq(1)').removeClass('hidden');

            if ($('#feedPreviewSection').is(':visible')){

                typePreviewElement.show('blind');
            }

            var feedURL = urlEle.val();
            if (waitForFileTypePreview && feedURL != "") {
                feedEditNS.renderFilePreviewSection(true);
            }
        },

        // In case of failure
        error:function(xhr, ajaxOptions, thrownError) {

            // Shows the error message
            showError(xhr.responseText);

            // Clears the preview section
            feedEditNS.clearTypePreviewSection();

            var feedURL = urlEle.val();
            if (waitForFileTypePreview && feedURL != "") {
                feedEditNS.renderFilePreviewSection(true);
            }
        }

Ajax コール B:

var renderFilePreviewPageRoute = jsRoutes.com.eyeview.connectad.controllers.solutions.FeedLibrary.getFeedFilePreviewPage(feedHashId);

    // Makes an ajax call that gets the rendered solution page
    $.ajax({

        // Sets the route (URL) of the server call
        url:renderFilePreviewPageRoute.url,

        // Sets the method (GET / POST) of the server call
        type:renderFilePreviewPageRoute.method,

        // In case of success
        success:function(result) {

            // Set the feed preview section html content to the rendered content got from the server
            $('#filePreviewSection').html(result);

            // Shows the feed preview section
            $('#verticalLine').show('blind');
            $('#leftShadow').show('blind');
            $('#rightShadow').show('blind');
            $('#feedPreviewSection').show('blind');

            feedEditNS.createDataTable(withHeaders);

            waitForFileTypePreview = false;
        },

        // In case of failure
        error:function(xhr, ajaxOptions, thrownError) {

            // Shows the error message
            showError(xhr.responseText);

            // Clears the preview section
            feedEditNS.clearFilePreviewSection();

            waitForFileTypePreview = false;
        }
4

2 に答える 2

0

問題を解決できませんでした。そのため、両方の呼び出しを 1 つのサーバー側メソッドへの 1 つの呼び出しに結合することになりました。このメソッドは、両方の通話応答を含む JSON オブジェクトを返しました。

于 2012-08-22T07:30:30.310 に答える
0

私はこの正確な問題に遭遇しました(3年後...)本当の問題が何であるかはまだわかりませんが、回避策としてsetTimeout()Angularコントローラー内で使用することになりました。

myApp.controller('myCtrl', function($scope, myRestApi) {

    $scope.restCallOne = function() {
        myRestApi.callOne().then(
            // handle result one
        );
    };

    $scope.restCallTwo = function() {
        myRestApi.callTwo().then(
            // handle result two
        );
    };

    // loads each time the view is shown
    // *** race condition when calling consecutively without a delay ***
    //$scope.restCallOne();
    setTimeout($scope.restCallOne, 100);
    $scope.restCallTwo();

});
于 2015-05-19T04:34:00.190 に答える