SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    AJAX, Which is better?

    Hi guys,

    PROS and CONS of these two below,

    1. AJAX (JavaScript no framework)
    2. AJAX (jQuery)

    Thanks in advance.
    Quality codes are optimized and tested...
    Click here for inspiration..

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,263
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    AFAIK jQuery AJAX is AJAX, just that it reduces the amount of code you need to write.
    But that's only because the code is already written and part of the jQuery library.

    IMHO if you need jQuery for other things then you might as well use it for AJAX too, but if you're loading the entire library for only AJAX, then it might be better to write your own AJAX code and use that to save on the bandwidth.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,870
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Unless you are going to use other parts of the jQuery framework then using plain JavaScript for your ajax call will result in the page needing to load far less code.

    Also while jQuery supports two of the ways to use ajax - httprequest and jsonp - it does not support other types of ajax call such as the two line plain JavaScript call to request a dummy image that can be used when you don't need a response from the server ( such as for a heartbeat script that tracks approximately when the person leaves your page).

    The cross browser issues that jQuery 1 handles with regard to ajax calls relate to the now long dead IE 4 through 6 browsers so you can make your plain JavaScript version shorter by omitting the code for those browsers (or if you decide to use jQuery then use version 2 instead of version 1).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    AJAX is one reason I would consider using the jQuery library.
    The syntax makes it so easy to work with, that it's more or less foolproof.
    If your worried about size, you can create a custom build, just including the AJAX functionality.

    Quote Originally Posted by felgall View Post
    Also while jQuery supports two of the ways to use ajax - httprequest and jsonp - it does not support other types of ajax call such as the two line plain JavaScript call to request a dummy image that can be used when you don't need a response from the server ( such as for a heartbeat script that tracks approximately when the person leaves your page).
    Interesting. Could you give me an example of what that might look like?

  5. #5
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the input guys.
    Quality codes are optimized and tested...
    Click here for inspiration..

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,870
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Pullo View Post
    Interesting. Could you give me an example of what that might look like?
    For an example of sending information to the server from JavaScript using a dummy image see http://javascriptexample.net/ajax08.php

    For a complete heartbeat script using a dummy image with JavaScript, PHP and mySQL see http://javascriptexample.net/ajax09.php
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,060
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Ok, thanks.


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
  •