Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Ajax Page Fetcher, Help Cancel Request

    Hallo i have been searching all over the web for an answer for this: are there a way to cancel a ajax request made with Cut & Paste Ajax Page Fetcher from JavaScript Kit ?

    Sincerely, kim

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,175
    Thanks
    23
    Thanked 601 Times in 600 Posts
    Depends on what you mean by cancel. Once the ajax request is started it must go through it's actions until it returns something from the server. You then could set the div the page will be displayed in to display:none; via a Cancel button. Done fast enough the user never sees the page at all.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The reason i need to "cancel" it is because of a other request is needed, but i will display the first request and the, the next one, if you understand what i mean ?

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,175
    Thanks
    23
    Thanked 601 Times in 600 Posts
    No I don't understand.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #5
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Okay, if you look at the picture.

    When i hover over Prison Architect and leaves that and hover over Space Engineers, then i want to drop or not display the request. so that i don't get it changing because one request came back an then change because another request came back. If you understand.





    Sorry for my poor English.

  • #6
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,175
    Thanks
    23
    Thanked 601 Times in 600 Posts
    The problem is what do you mean by "request".
    When youi hover over the "Prison Architect" image what happens? and how does it happen (code please).
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #7
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here are the code i use to trigger it

    The "data-steam" is just the app id of the game


    Code:
    $(function() {
    
    $('a.popper').mouseenter(function(e) {
    
    	
    	document.getElementById('steam_game_info').innerHTML='Please wait loading content . . . <br /> <img src="../../infusions/steam/images/loading.gif" alt="" />';
    	
    	var url = '../../infusions/steam/load_content/steam_game_info.php?id=';
        var data = $(this).attr('data-steam');
    
        ajaxpagefetcher.load('steam_game_info', url + data, true);
    	console.log('...')
    });
    
    $('a.popper').mouseleave(function(e) {
    
    
    });
    });

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    XMLHttpRequest has abort() method. I'm not sure about Microsoft.XMLHTTP for IE6 (I'm sure you don't care about IE6, do you?)

    You have to modify the ajaxpagefetcher script to return the page_request instance.

    Code:
    var ajaxpagefetcher={
    loadingmessage: "Loading Page, please wait...",
    exfilesadded: "",
    
    connect:function(containerid, pageurl, bustcache, jsfiles, cssfiles){
    	var page_request = false
    	var bustcacheparameter=""
    	if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
    		page_request = new XMLHttpRequest()
    	else if (window.ActiveXObject){ // if IE6 or below
    		try {
    		page_request = new ActiveXObject("Msxml2.XMLHTTP")
    		} 
    		catch (e){
    			try{
    			page_request = new ActiveXObject("Microsoft.XMLHTTP")
    			}
    			catch (e){}
    		}
    	}
    	else
    		return false
    	var ajaxfriendlyurl=pageurl.replace(/^http:\/\/[^\/]+\//i, "http://"+window.location.hostname+"/") 
    	page_request.onreadystatechange=function(){ajaxpagefetcher.loadpage(page_request, containerid, pageurl, jsfiles, cssfiles)}
    	if (bustcache) //if bust caching of external page
    		bustcacheparameter=(ajaxfriendlyurl.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
    	document.getElementById(containerid).innerHTML=ajaxpagefetcher.loadingmessage //Display "fetching page message"
    	page_request.open('GET', ajaxfriendlyurl+bustcacheparameter, true)
    	page_request.send(null);
    	return page_request;
    },
    
    ...
    ...
    
    load:function(containerid, pageurl, bustcache, jsfiles, cssfiles){
    	var jsfiles=(typeof jsfiles=="undefined" || jsfiles=="")? [] : jsfiles
    	var cssfiles=(typeof cssfiles=="undefined" || cssfiles=="")? [] : cssfiles
    	return this.connect(containerid, pageurl, bustcache, jsfiles, cssfiles)
    }
    
    } //End object
    Then
    Code:
    $(function () {
    
        var ajax;
    
        $('a.popper').mouseenter(function (e) {
    
    
            document.getElementById('steam_game_info').innerHTML = 'Please wait loading content . . . <br /> <img src="../../infusions/steam/images/loading.gif" alt="" />';
    
            var url = '../../infusions/steam/load_content/steam_game_info.php?id=';
            var data = $(this).attr('data-steam');
    
            ajax = ajaxpagefetcher.load('steam_game_info', url + data, true);
            console.log('...')
        })
    
        $('a.popper').mouseleave(function (e) {
            if (ajax) ajax.abort();
    
        });
    });

  • Users who have thanked glenngv for this post:

    zicy (01-30-2014)

  • #9
    New to the CF scene
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you it works perfect


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •