SitePoint Sponsor

User Tag List

Page 2 of 4 FirstFirst 1234 LastLast
Results 26 to 50 of 85
  1. #26
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Sydney, Australia
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use the following script to create my XMLHTTPRequest Object. It'll set the variable to false if it's got nothing.

    Code:
    // XMLHttpRequest function to initiate request object
    function AJAX() {		
    	var o = false;
    	/*@cc_on @*/
    	/*@if (@_jscript_version >= 5)
     		try {
      			o = new ActiveXObject("Msxml2.XMLHTTP");
     		} catch (e) {
      			try {
       				o = new ActiveXObject("Microsoft.XMLHTTP");
      			} catch (E) {
       				o = false;
      			}
     		}
    	@end @*/
    	if (!o && typeof XMLHttpRequest!='undefined') {
    		o = new XMLHttpRequest();
    	}
    	
    	return o;
    }
    Note the conditional compilation - that should handle all types of Internet Explorer.

  2. #27
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Sydney, Australia
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this for creation of an XMLHTTPRequest object. It uses conditional compilation (inside JS comments) to take care of IE.

    The function will also return false if it can't create the object, so you can check whether it's setup before attempting to retrieve anything.

    Code:
    // XMLHttpRequest function to initiate request object
    function AJAX() {		
    	var o = false;
    	/*@cc_on @*/
    	/*@if (@_jscript_version >= 5)
     		try {
      			o = new ActiveXObject("Msxml2.XMLHTTP");
     		} catch (e) {
      			try {
       				o = new ActiveXObject("Microsoft.XMLHTTP");
      			} catch (E) {
       				o = false;
      			}
     		}
    	@end @*/
    	if (!o && typeof XMLHttpRequest!='undefined') {
    		o = new XMLHttpRequest();
    	}
    	
    	return o;
    }

  3. #28
    SitePoint Member
    Join Date
    Jun 2004
    Location
    Sydney, Australia
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    D'oh. Having a little trouble with the forum/article cross-posting paradigm.

    I need more coffee. :P

  4. #29
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Dordrecht, Netherlands
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but why does it not re-check the receipt ?? (for when there are more
    possible receipts to be entered)

    Edit:


    I just found out that it does re-check with the receipt.php when the name field is emptied (verb of "to emtpy" ? ) and when the receipt number is changed.. how can I recheck and change by just changing the receipt field ?


    Edit:


    also I found out that if the name OR email is empty, neither the name or email will be punt in the input fields..
    Last edited by whitehouse; Jul 19, 2005 at 03:12.

  5. #30
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Location
    Rosario, Argentina
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Excelent, so cool!!!

  6. #31
    SitePoint Enthusiast
    Join Date
    Sep 2003
    Location
    Australia
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice, clear, simple article.

  7. #32
    SitePoint Enthusiast RaS!'s Avatar
    Join Date
    Mar 2004
    Location
    Italy
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Damn cool article, good job!

  8. #33
    julienmassillia@gmail.com
    SitePoint Community Guest
    Hi everyone !! ,
    I read it , and liked it , but would it be possible to implment it with mysql , to create some kind if search ?

    Thanks julien

  9. #34
    SitePoint Author
    Join Date
    Jul 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Julien,

    To implement a database-driven remote scripting search module would mostly be a tutorial on server-side code. XMLHttpRequest itself is relatively simple, and a search engine would be remarkably similar to the example application here -- send off your search query to a server-side script, receive an XML file with the results and write it into your page.

    The most complex (or should I say time-consuming) JavaScript part of it would be the creation of the search results HTML. Stuart Langridge's "DHTML Utopia" book would contain enough handy hints on navigating and creating DOM elements if you'd like to know more about that.

  10. #35
    Ben
    SitePoint Community Guest
    This was the right article at the right time. I was needing this exact mechanism. Very informative.

    One newbie question though: is there any way to return an image (say, a PNG) as responseText and then display that?

  11. #36
    SitePoint Zealot Ghandi's Avatar
    Join Date
    Sep 2002
    Location
    Kansas
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in IE I have a problem with div.innerHTML = requester.responseText; it seems to cut off the XML doctype and a several of the first tags.

    Works fine in FireFox though....
    W.W.G.D. :: What Would Gandhi Do
    http://patkohler.blogspot.com/

  12. #37
    SitePoint Guru worchyld's Avatar
    Join Date
    Jul 2003
    Location
    Newcastle upon Tyne
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't get AJAX -- doesn't it rely on JavaScript and Client-side? What happens if JS is down, broken and ill-defined? Or if the browser person has switched off J/S...?

  13. #38
    SitePoint Zealot Ghandi's Avatar
    Join Date
    Sep 2002
    Location
    Kansas
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then you could do some <noscript></noscript> stuff
    W.W.G.D. :: What Would Gandhi Do
    http://patkohler.blogspot.com/

  14. #39
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ben:

    Yes, but it would be simpler to create a new image tag and point it to the URL (or change the backgroundImage class attribute).

  15. #40
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jimfraser:

    Thanks. Sounds like my approach wasn't that far off. Creating a new image is essentially what I'm doing . A little context: I'm implementing a historical maps site. Maps may take a second or two to generate, so I'm using the XMLHttpRequest to trigger the map rendering and tell me when the maps have finished drawing and I can retrieve them. (If anyone has a suggestion for a more efficient method, I'm all ears).

  16. #41
    SitePoint Enthusiast
    Join Date
    Aug 2003
    Location
    Canada
    Posts
    93
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the great article, this is probably the first I've heard of this concept.

    While one could likely accomplish the same thing via a hidden <iframe> or something of that nature, I like that this can be made completely invisible to the user (an iframe would cause a "click" in IE and a "working in background" cursor). Very slick.

    Now I know how Google made GMail so blazing fast!

    I don't get AJAX -- doesn't it rely on JavaScript and Client-side? What happens if JS is down, broken and ill-defined? Or if the browser person has switched off J/S...?
    Then the user needs to upgrade that ol' 386 ;)

  17. #42
    david
    SitePoint Community Guest
    why doesn't my simple script work?

    Code:
    function getNumber() {
    	try {
    		var requester = new XMLHttpRequest();
    	} catch (error) {
    		//alert(error);
    		try {
    			var requester = new ActiveXObject("Microsoft.XMLHTTP");
    		} catch (error) {
    			alert(error);
    			return false;
    		}
    	}
    	
    	requester.open("GET", "server.asp");
    	requester.send(null);
    	
    	if(requester.readyState == 4) {
    		if (requester.status == 200) {
    			requester.onreadystatechange = true;
    			alert(requester.responseText);
    		}//stateHandler();
    	}
    }

  18. #43
    Josh
    SitePoint Community Guest
    Thanks so much, I was wondering how all this stuff was done! Following this tutorial but applying the concepts to my own project (a private message notifier for my forum) the results worked first time!! Whoo!

  19. #44
    Ned Collyer
    SitePoint Community Guest
    Dave: you dont have a ready state handler.

    When you set requester.onreadystatechange to the handler, the handler function gets called every time requester.readyState is changed.

    At the moment, the script tests only once for the readyState being 4, what it needs to do is run every time the state changes.

    Rgds

    Ned

  20. #45
    andy
    SitePoint Community Guest
    Excellent article

  21. #46
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice article. It was a good reference as I built my first AJAX application. Though I opted not to use innerHTML.

    I thought I would get screams from it's users about it not working but so far, everyone says it works great. Compared to the old version of the app I converted, I went from downloading 10kb of graphics, markup and content per click while using an iframe. To about 500-600 bytes of data only. That's quite a difference.

  22. #47
    klokkie
    SitePoint Community Guest
    Give me a good indication of what AJAX etc. is about...
    Thanks

  23. #48
    Khan
    SitePoint Community Guest
    awesome article, thanks.

  24. #49
    Matt
    SitePoint Community Guest
    Excellent introduction : thanks

  25. #50
    SitePoint Enthusiast pff's Avatar
    Join Date
    Dec 2000
    Location
    Google PageRank: 6
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The article is great but to make this part work with PHP:
    To send CGI variables using the POST request method, the CGI variables can be passed to the send() method like so:

    requester.open("POST", "/query.cgi");
    requester.send("name=Bob&email=bob@example.com");
    Try this instead:

    requester.open("POST", "/query.php");
    requester.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    requester.send(name=Bob&email=bob@example.com);

    pff | I am not what I am

    'Does he exist in the same way as I exist?'
    'You do not exist Winston,' said O'Brien.


Bookmarks

Posting Permissions

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