Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita1e619b

Browse files
authored
Ajax: Execute JSONP error script responses
Issuegh-4379 was meant to be a bug fix but the JSONP case is a bit special:under the hood it's a script but it simulates JSON responses in an environmentwithout a CORS setup and sending JSON payloads on error responses is quitetypical there.This commit makes JSONP error responses still execute the payload. The regularscript error responses continue to be skipped.Fixesgh-4771Closesgh-4773
1 parent07a8e4a commita1e619b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

‎src/ajax.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,10 @@ jQuery.extend( {
746746
response=ajaxHandleResponses(s,jqXHR,responses);
747747
}
748748

749-
// Use a noop converter for missing script
750-
if(!isSuccess&&jQuery.inArray("script",s.dataTypes)>-1){
749+
// Use a noop converter for missing script but not if jsonp
750+
if(!isSuccess&&
751+
jQuery.inArray("script",s.dataTypes)>-1&&
752+
jQuery.inArray("json",s.dataTypes)<0){
751753
s.converters["text script"]=function(){};
752754
}
753755

‎test/unit/ajax.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,19 @@ QUnit.module( "ajax", {
810810
};
811811
});
812812

813+
ajaxTest("jQuery.ajax() - do execute scripts if JSONP from unsuccessful responses",1,function(assert){
814+
vartestMsg="Unsuccessful JSONP requests should have a JSON body";
815+
return{
816+
dataType:"jsonp",
817+
url:url("mock.php?action=errorWithScript"),
818+
// error is the significant assertion
819+
error:function(xhr){
820+
varexpected={"status":404,"msg":"Not Found"};
821+
assert.deepEqual(xhr.responseJSON,expected,testMsg);
822+
}
823+
};
824+
});
825+
813826
ajaxTest("jQuery.ajax() - do not execute scripts from unsuccessful responses (gh-4250)",11,function(assert){
814827
varglobalEval=jQuery.globalEval;
815828

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp