所以我对一个控制器有两个嵌套的AJAX请求。
$(this).click(function(){
$('#test_pass_image').show();
$.ajax({
type: 'POST',
beforeSend: function(request) {
request.setRequestHeader('X-CSRF-Token', $( 'meta[name="csrf-token"]' ).attr( 'content' ));
},
dataType:'json',
data: {
'project_id':"<%= @project_id %>",
'test_id' : "<%= @test_id %>"
},
url: encodeURI('/test_pass'),
success: function(){
alert('success');
$.ajax({
type: 'POST',
beforeSend: function(request) {
request.setRequestHeader('X-CSRF-Token', $( 'meta[name="csrf-token"]' ).attr( 'content' ));
},
dataType: 'json',
data: {
'project_id':"<%= @project_id %>",
'test_id' : "<%= @test_id %>"
},
url: encodeURI('/test_next_load/'),
success: function(){}
})
}
})
});
现在, 当第一个POST(/ test_pass)没有View时,会发出alert('success'),并发出第二个POST请求。
Started POST "/test_pass" for ::1 at 2019-07-02 18:37:01 +0200
Processing by TestsController#test_pass as JSON
Parameters: {"project_id"=>"1", "test_id"=>"1"}
No template found for TestsController#test_pass, rendering head :no_content
Completed 204 No Content in 207ms (ActiveRecord: 179.7ms)
Started POST "/test_next_load/" for ::1 at 2019-07-02 18:37:04 +0200
Processing by TestsController#test_next_load as JSON
Parameters: {"project_id"=>"1", "test_id"=>"1"}
Rendering tests/test_next_load.js.erb
Rendered tests/test_next_load.js.erb (0.4ms)
Completed 200 OK in 10ms (Views: 2.1ms | ActiveRecord: 1.0ms)
但是,尽管彪马说了什么,test_next_load.js.erb仍未呈现。 页面上没有任何变化。 而且浏览器上没有js错误
但是,如果第一个POST确实具有视图,例如alert('first'),
它不会呈现第一个,也不会进入成功条件,并且显然也不会呈现第二个。
我发现了一些奇怪的响应头
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 31f62df6-3e33-448b-baae-365a3ecf3bdd
X-Runtime: 0.127960
X-XSS-Protection: 1; mode=block
我认为部分是问题所在。我如何取消这些设置? (noopen)
但是我并不热衷于更改它们,因为它们可能掩盖了一些不良的配置或错误,并看到了奇怪的渲染情况。