heres a snipset of what im trying to do
$.pjax = function( options ) {
var $container = $(options.container),
success = options.success || $.noop
// We don't want to let anyone override our success handler.
delete options.success
// We can't persist $objects using the history API so we must use
// a String selector. Bail if we got anything else.
if ( typeof options.container !== 'string' )
throw "pjax container must be a string selector!"
var defaults = {
timeout: 650,
push: true,
replace: false,
// We want the browser to maintain two separate internal caches: one for
// pjax'd partial page loads and one for normal page loads. Without
// adding this secret parameter, some browsers will often confuse the two.
data: { _pjax: true },
type: 'GET',
dataType: 'html',
beforeSend: function(xhr){
$container.trigger('start.pjax')
xhr.setRequestHeader('X-PJAX', 'true')
},
error: function(){
window.location = options.url
},
complete: function(){
$container.trigger('end.pjax')
},
success: function(data){
// If we 开发者_开发问答got no data or an entire web page, go directly
// to the page and let normal error handling happen.
if ( !$.trim(data) || /<html/i.test(data) )
return window.location = options.url
// Make it happen.
// i think im not getting it right.
$(window).load(
function() {
$container.html(data)
}
);
like Official way to ask jQuery wait for all images to load before executing something but its after an jquery ajax request.
as you can see at the bottom // Make it happen
, im trying to return the html(data) after its all image from the html(data) is ready to serve, can we do that somehow?
thanks!
Adam Ramadhan
I believe you will have to insert the loaded HTML into the DOM before the browser will start loading any of the images. You should be able to insert it into a hidden (display:none
) div, and set the .load()
callback on that hidden div.
This plugin improves the .load()
event so that it is more consistently triggered on image loading.
精彩评论