jqueryajax使用Play调用冲突!框架
在页面中调用某个操作时,我会对服务器上的两个不同方法进行两次ajax调用(A、B)。 大多数情况下,每个请求都会得到匹配的响应,但在这里和那里,两个请求都会得到相同的响应!(指其中一项要求-A、A或B、B) Ajax调用使用JQuery进行,服务器方法使用Play实现!框架(java) 有人知道为什么会发生这种情况以及如何解决吗 谢谢 Ajax调用A:jqueryajax使用Play调用冲突!框架,ajax,jquery,playframework,Ajax,Jquery,Playframework,在页面中调用某个操作时,我会对服务器上的两个不同方法进行两次ajax调用(A、B)。 大多数情况下,每个请求都会得到匹配的响应,但在这里和那里,两个请求都会得到相同的响应!(指其中一项要求-A、A或B、B) Ajax调用使用JQuery进行,服务器方法使用Play实现!框架(java) 有人知道为什么会发生这种情况以及如何解决吗 谢谢 Ajax调用A: var renderTypePreviewPageRoute = jsRoutes.com.eyeview.connectad.controll
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;
}
我无法解决这个问题。 因此,我最终将两个调用合并为一个对单个服务器端方法的调用。
这个方法返回了一个包含两个调用和应答的JSON对象。我遇到了这个问题(3年后…)我仍然不确定真正的问题是什么,但作为一种解决方法,我最终在我的角度控制器中使用了
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();
});
对我来说,这是Javascript代码中的一个错误。给我们看看相关的linesHi!谢谢你的快速回答。在上面添加了我的两个Jquery ajax调用。如果代码中有错误,那么它在大多数情况下是如何工作的,并且只有在少数情况下我得到相同的响应?…嗯,这样很难说。首先,确保您实际触发了两个不同的HTTP请求。您可以通过Chrome inspector或Firebug扩展为FF。然后,在同一个面板中,检查响应以再次检查它们是否不同。最后,请确切解释为什么它们都返回相同的数据。这是一个用户界面的东西吗?你检查过调试器了吗?我检查了Chrome和FF中的两个答案。在这两种情况下,我都看到两个事件被触发。大多数时候,当我查看回复时,我看到有两种不同的内容。但在其他一些情况下,我在响应中看到了相同的内容(尽管它指向两个不同的URL-REST)