Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

XMLHttpRequest question.

  • 01-01-2005 09:31AM
    #1
    Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭


    Ok when I run this the responseText is set as "undefined". It should be text. Anyone know what I'm missing?
    var gXMLHttpRequest;
    
    function loadUp() {
    	gXMLHttpRequest = new XMLHttpRequest();
    	gXMLHttpRequest.onload = updateID;
    	gXMLHttpRequest.open("GET", "http://members.boards.ie/dokkaebi/pmtest.txt");
    	gXMLHttpRequest.send(null);
    
    //	window.setTimeout(loadUp, 1800000);
    }
    
    //window.setTimeout(loadUp, 1000);
    
    function updateID()
    {
      	var pageText = XMLHttpRequest.responseText;
      	alert(pageText);
    }
    


Comments

  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Ack so bloody simple, amazed I missed it :(

    Someone at mozilla told me...

    var pageText = gXMLHttpRequest.responseText;


  • Registered Users, Registered Users 2 Posts: 1,785 ✭✭✭Farls


    Always the simple ones take the longest to figure! Surprised a noob didn't get it.

    "School boy errors" eh!

    Farlz


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Actually my next question is.. How do you pass a cookie to the site your accessing?

    Trying to access usercp, however all it gets is the not logged in page, yet the browser is logged in.


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Hobbes wrote:
    Actually my next question is.. How do you pass a cookie to the site your accessing?
    HTTP Headers for the request can be set with the setRequestHeader method.


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Cheers. appears there is a little more involved then that. I'll post solution once I get it working.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    Here it is. Once you activate the cookie manager and pull in the cookies you want then the XMLHttpRequest will pull the required cookies from that. Example below pulls all boards.ie cookies before requesting userCP.
    function getQueryString() {
    	// Get the cookie.
    	var ioService = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
    	var cookieManager = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
    	var uri = ioService.newURI("http://www.boards.ie", null, null); 
    	cookieString = cookieManager.getCookieString(uri, null);
    	
    	gXMLHttpRequest = new XMLHttpRequest();
    	gXMLHttpRequest.onload = updatePMCheck;
    	
    	gXMLHttpRequest.open("GET", "http://www.boards.ie/vbulletin/usercp.php?");
    	gXMLHttpRequest.send(null);
    }
    


Advertisement