JQuery ajax使用Play调用碰撞!骨架

时间:2012-08-19 07:57:49

标签: ajax jquery playframework

当在我的页面中调用某个动作时,我在我的服务器上对两个不同的方法进行两次ajax调用(A,B)。 大多数情况下,每个请求都会得到匹配的响应,但是这两个请求都会得到相同的响应! (其中一项请求 - A,A或B,B)

Ajax调用是使用JQuery进行的,服务器方法是使用Play实现的!框架(在java中)。

有没有人知道它为什么会发生以及如何解决它?

谢谢!

Ajax Call 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 Call 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;
        }

2 个答案:

答案 0 :(得分:0)

我无法解决问题。 因此,我最终将两个调用组合成一个调用单个服务器端方法。 此方法返回一个包含两个调用答案的JSON对象。

答案 1 :(得分:0)

我遇到了这个确切的问题(3年后......)我仍然不确定真正的问题是什么,但作为一种解决方法,我最终在我的Angular控制器中使用setTimeout()

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();

});