Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
95291b44
Commit
95291b44
authored
May 01, 2012
by
Oleg
Committed by
Rick Waldron waldron.rick@gmail.com
May 01, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jQuery.fn.load optimization
parent
6bed348a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
47 deletions
+38
-47
ajax.js
src/ajax.js
+38
-47
No files found.
src/ajax.js
View file @
95291b44
...
...
@@ -158,72 +158,63 @@ jQuery.fn.extend({
load
:
function
(
url
,
params
,
callback
)
{
if
(
typeof
url
!==
"string"
&&
_load
)
{
return
_load
.
apply
(
this
,
arguments
);
}
// Don't do a request if no elements are being requested
}
else
if
(
!
this
.
length
)
{
if
(
!
this
.
length
)
{
return
this
;
}
var
off
=
url
.
indexOf
(
" "
);
var
selector
,
type
,
self
=
this
,
off
=
url
.
indexOf
(
" "
);
if
(
off
>=
0
)
{
var
selector
=
url
.
slice
(
off
,
url
.
length
);
selector
=
url
.
slice
(
off
,
url
.
length
);
url
=
url
.
slice
(
0
,
off
);
}
//
Default to a GET request
var
type
=
"GET"
;
//
If it's a function
if
(
jQuery
.
isFunction
(
params
)
)
{
// If the second parameter was provided
if
(
params
)
{
// If it's a function
if
(
jQuery
.
isFunction
(
params
)
)
{
// We assume that it's the callback
callback
=
params
;
params
=
undefined
;
// We assume that it's the callback
callback
=
params
;
params
=
undefined
;
// Otherwise, build a param string
}
else
if
(
typeof
params
===
"object"
)
{
type
=
"POST"
;
}
// Otherwise, build a param string
}
else
if
(
typeof
params
===
"object"
)
{
type
=
"POST"
;
}
var
self
=
this
;
// Request the remote document
jQuery
.
ajax
({
url
:
url
,
// if "type" variable is undefined, then "GET" method will be used
type
:
type
,
dataType
:
"html"
,
data
:
params
,
// Complete callback (responseText is used internally)
complete
:
function
(
jqXHR
,
status
,
responseText
)
{
// Store the response as specified by the jqXHR object
responseText
=
jqXHR
.
responseText
;
// If successful, inject the HTML into all the matched elements
if
(
jqXHR
.
isResolved
()
)
{
// #4825: Get the actual response in case
// a dataFilter is present in ajaxSettings
jqXHR
.
done
(
function
(
r
)
{
responseText
=
r
;
});
// See if a selector was specified
self
.
html
(
selector
?
// Create a dummy div to hold the results
jQuery
(
"<div>"
)
// inject the contents of the document in, removing the scripts
// to avoid any 'Permission Denied' errors in IE
.
append
(
responseText
.
replace
(
rscript
,
""
))
// Locate the specified elements
.
find
(
selector
)
:
// If not, just inject the full result
responseText
);
}
data
:
params
}).
done
(
function
(
responseText
)
{
if
(
callback
)
{
self
.
each
(
callback
,
[
responseText
,
status
,
jqXHR
]
);
}
// See if a selector was specified
self
.
html
(
selector
?
// Create a dummy div to hold the results
jQuery
(
"<div>"
)
// inject the contents of the document in, removing the scripts
// to avoid any 'Permission Denied' errors in IE
.
append
(
responseText
.
replace
(
rscript
,
""
)
)
// Locate the specified elements
.
find
(
selector
)
:
// If not, just inject the full result
responseText
);
}).
always
(
function
()
{
if
(
callback
)
{
self
.
each
(
callback
,
arguments
);
}
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment