🌐 AI搜索 & 代理 主页
Skip to content

Commit 467cea1

Browse files
committed
Ajax: removing support.responseURL
1 parent bb6cae8 commit 467cea1

File tree

3 files changed

+30
-53
lines changed

3 files changed

+30
-53
lines changed

src/ajax/xhr.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
define( [
22
"../core",
3-
"../var/support",
43
"../ajax"
5-
], function( jQuery, support ) {
4+
], function( jQuery ) {
65

76
"use strict";
87

@@ -16,10 +15,7 @@ var xhrSuccessStatus = {
1615

1716
// File protocol always yields status code 0, assume 200
1817
0: 200
19-
},
20-
xhrSupported = jQuery.ajaxSettings.xhr();
21-
22-
support.responseURL = !!xhrSupported && ( "responseURL" in xhrSupported );
18+
};
2319

2420
jQuery.ajaxTransport( function( options ) {
2521
var callback;
@@ -84,7 +80,7 @@ jQuery.ajaxTransport( function( options ) {
8480
complete(
8581
xhrSuccessStatus[ xhr.status ] || xhr.status,
8682
xhr.statusText,
87-
support.responseURL ? xhr.responseURL : "",
83+
xhr.responseURL,
8884

8985
// For XHR2 non-text, let the caller handle it (gh-2498)
9086
( xhr.responseType || "text" ) === "text" ?

test/unit/ajax.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,17 +1409,12 @@ QUnit.module( "ajax", {
14091409
} );
14101410

14111411
ajaxTest( "jQuery.ajax() - responseURL", 13, function( assert ) {
1412-
function expectedUrl( url ) {
1413-
return jQuery.support.responseURL ? url : "";
1414-
}
14151412

1416-
/**
1417-
* this function generates complete
1418-
* absolute URL without any relative path components
1419-
* example:
1420-
* input: http://localhost:9876/base/test/data/testinit.js/../../../test/data/mock.php?action=responseURL&155821644568982930
1421-
* output: http://localhost:9876/base/test/data/mock.php?action=responseURL&155821644568982930
1422-
*/
1413+
// This function generates complete
1414+
// absolute URL without any relative path components
1415+
// Example:
1416+
// Input: http://localhost:9876/base/test/data/testinit.js/../../../test/data/mock.php?action=responseURL&155821644568982930
1417+
// Output: http://localhost:9876/base/test/data/mock.php?action=responseURL&155821644568982930
14231418
function removeRelativePathComponents( url ) {
14241419
var reg = RegExp( "(\\.\\.\\/)+" ), match;
14251420
match = reg.exec( url );
@@ -1433,25 +1428,25 @@ QUnit.module( "ajax", {
14331428
return url;
14341429
}
14351430

1436-
var successUrl = removeRelativePathComponents( url( "mock.php?action=responseURL" ) ),
1437-
errorUrl = "http://example.invalid",
1438-
redirectAndSuccessUrl = removeRelativePathComponents( url( "mock.php?action=responseURL" ) ) + "&url=" + encodeURIComponent( successUrl ),
1439-
redirectAndErrorUrl = url( "mock.php?action=responseURL&url=" + encodeURIComponent( errorUrl ) ),
1440-
jsonpUrl = url( "mock.php?action=jsonp&callback=?" ),
1441-
scriptUrl = url( "mock.php?action=testbar" );
1431+
var successURL = removeRelativePathComponents( url( "mock.php?action=responseURL" ) ),
1432+
errorURL = "http://example.invalid",
1433+
redirectAndSuccessURL = url( "mock.php?action=responseURL" ) + "&url=" + encodeURIComponent( successURL ),
1434+
redirectAndErrorURL = url( "mock.php?action=responseURL&url=" + encodeURIComponent( errorURL ) ),
1435+
jsonpURL = url( "mock.php?action=jsonp&callback=?" ),
1436+
scriptURL = url( "mock.php?action=testbar" );
14421437

14431438
return [
14441439
{
1445-
url: successUrl,
1446-
beforeSend: function( jqXHR, settings ) {
1440+
url: successURL,
1441+
beforeSend: function( jqXHR ) {
14471442
assert.strictEqual( jqXHR.responseURL, "", "jqXHR responseURL ok before sending request" );
14481443
},
14491444
success: function( _, __, jqXHR ) {
1450-
assert.strictEqual( jqXHR.responseURL, expectedUrl( successUrl ), "jqXHR responseURL ok for success" );
1445+
assert.strictEqual( jqXHR.responseURL, successURL, "jqXHR responseURL ok for success" );
14511446
}
14521447
},
14531448
{
1454-
url: errorUrl,
1449+
url: errorURL,
14551450
beforeSend: function( jqXHR ) {
14561451
assert.strictEqual( jqXHR.responseURL, "", "jqXHR responseURL ok before sending request" );
14571452
},
@@ -1460,16 +1455,16 @@ QUnit.module( "ajax", {
14601455
}
14611456
},
14621457
{
1463-
url: redirectAndSuccessUrl,
1458+
url: redirectAndSuccessURL,
14641459
beforeSend: function( jqXHR ) {
14651460
assert.strictEqual( jqXHR.responseURL, "", "jqXHR responseURL ok before sending request" );
14661461
},
14671462
success: function( _, __, jqXHR ) {
1468-
assert.strictEqual( jqXHR.responseURL, expectedUrl( successUrl ), "jqXHR responseURL ok for redirect success" );
1463+
assert.strictEqual( jqXHR.responseURL, successURL, "jqXHR responseURL ok for redirect success" );
14691464
}
14701465
},
14711466
{
1472-
url: redirectAndErrorUrl,
1467+
url: redirectAndErrorURL,
14731468
beforeSend: function( jqXHR ) {
14741469
assert.strictEqual( jqXHR.responseURL, "", "jqXHR responseURL ok before sending request" );
14751470
},
@@ -1478,7 +1473,7 @@ QUnit.module( "ajax", {
14781473
}
14791474
},
14801475
{
1481-
url: jsonpUrl,
1476+
url: jsonpURL,
14821477
dataType: "jsonp",
14831478
crossDomain: true,
14841479
beforeSend: function( jqXHR ) {
@@ -1492,7 +1487,7 @@ QUnit.module( "ajax", {
14921487
setup: function() {
14931488
Globals.register( "testBar" );
14941489
},
1495-
url: scriptUrl,
1490+
url: scriptURL,
14961491
dataType: "script",
14971492
crossDomain: true,
14981493
beforeSend: function( jqXHR ) {

test/unit/support.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,18 @@ testIframe(
5656

5757
( function() {
5858
var expected,
59-
version,
6059
userAgent = window.navigator.userAgent,
6160
expectedMap = {
62-
edge: {
63-
responseURL:true
64-
},
65-
ie_11: {
66-
responseURL:false
67-
},
68-
chrome: {
69-
responseURL:true
70-
},
71-
safari: {
72-
responseURL:true
73-
},
74-
firefox: {
75-
responseURL:true
76-
},
77-
ios: {
78-
responseURL:true
79-
}
61+
edge: {},
62+
ie_11: {},
63+
chrome: {},
64+
safari: {},
65+
firefox: {},
66+
ios: {}
8067
};
8168

8269
if ( /edge\//i.test( userAgent ) ) {
83-
version = parseInt( ( /edge\/([0-9.]+)/i ).exec( navigator.userAgent )[ 1 ] );
8470
expected = expectedMap.edge;
85-
expected.responseURL = version >= 14;
8671
} else if ( document.documentMode ) {
8772
expected = expectedMap.ie_11;
8873
} else if ( /chrome/i.test( userAgent ) ) {
@@ -96,6 +81,7 @@ testIframe(
9681
} else if ( /(?:iphone|ipad);.*(?:iphone)? os \d+_/i.test( userAgent ) ) {
9782
expected = expectedMap.ios;
9883
}
84+
9985
QUnit.test( "Verify that support tests resolve as expected per browser", function( assert ) {
10086
if ( !expected ) {
10187
assert.expect( 1 );

0 commit comments

Comments
 (0)