Jump to content

Resources


neylitalo
 Share

Recommended Posts

  • 2 weeks later...
Good resources.

While pre-build AJAX libraries/wrappers/frameworks whatever you call it, might be a nice thing - I wouldn't recommend them for people just starting out with AJAX. There's a couple of reasons for that.. one being that you don't get to understand how AJAX workes without writing the code yourself. Even if you're just writing the examples off a book word by word (as I tend to do), while doing that you learn what each function does and how they're named etc. it's good practise :D. For the user that knows all this, by all means use these libraries if it helps faster development.

Also some very nice AJAX/Javascript/PHP tutorials on this site: http://www.ajaxprojects.com/ and other goodies.
Link to comment
Share on other sites

Thanks for the comments.  I tend to agree with you that people should be writing their own code when they start out.  It helps to understand the client/server interaction and helps tremendously in the debugging process!

I'm going to copy your link into the opening post.
Link to comment
Share on other sites

  • 4 months later...
  • 3 months later...
One thing I want to throw out there: Javascript (as I've tested in IE 6, Firefox, and Opera) has the funcions escape() and unescape() defined, meaning they are built-in functions. Therefore, you don't have to write your own encoding/decoding functions to make your GET/POST data url-safe.
Example:
[code]var title="The End";
var html="Hurrah!<br>And so it goes & goes! I ain't no sore, not @ the world no more. Url: \"index.php?page=etc&stuff=2\"";
url="index.php?page=etc&title="+escape(title)+"&html="+escape(html);[/code]
Nothing complicated about it.
Link to comment
Share on other sites

  • 2 months later...
  • 5 months later...
  • 4 months later...
  • 3 weeks later...
  • 2 weeks later...
  • 1 month later...

Keeping as backup for reference AJAX standard for quick uses.

 

/**
* @xmlHttp used to ajax handle
* --------------------------------------------
* Default STandard use
*/

var xmlHttp;

/**
* @ajax_maincall
* Call this from your HTML events
*/
function ajax_main(){
    // Create ajax
    ajax_connect(2,2,3,4);
    /* 
     * Start auto reload 
     * In case of real time data query
     * Optional
     */
    ajax_listen();
}

/**
* @GetXmlHttpObject used to detect the browser
* Supported - Firefox, Opera , Safari, IE
*
*/
function GetXmlHttpObject(){
  var xmlHttp=null;
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }catch (e){
    // Internet Explorer
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

/**
* @ajax_connect
* Use query mysql data or other
* by php, asp, jsp
*/
function ajax_connect(str1, str2, str3, str4){
  // Set xmlHttp object for browser
  xmlHttp=GetXmlHttpObject();
  // Condition for browser
  if (xmlHttp==null){
    alert ("This browser does not support AJAX!");
    return;
  }
  /* 
   * Variable setup for php or asp or jsp
   */
  var url="username_password_others.php";
  url=url+"?str1="+str1+"&str2="+str2+"&q3="+str3+"&q4="+str4;
  // Must be used , dont change for caching
  url=url+"&sid="+Math.random();

  /* 
   * Call output event
   * Query output represent
   * *condition can be removed
   */
  if(str1=="2"){
      xmlHttp.onreadystatechange=ajax_dataarival1;
  }else{
    xmlHttp.onreadystatechange=ajax_dataarival2;
  }
  // Execute GET method
  xmlHttp.open("GET",url,true);
  // Send Get or Post method
  xmlHttp.send(null);
}

/**
* @ajax_dataarival1
* Login failure
*
*/
function ajax_dataarival1(){
  if (xmlHttp.readyState==4){
      // Will replace the mother page.
      // html: <div id="s1"> replace me </div> 
      $tim = time();
      document.getElementById("s1").innerHTML=$tim;
  }
}

/**
* @ajax_dataarival2
* Login failure
*
*/
function ajax_dataarival2(){
  if (xmlHttp.readyState==4){
      // Will replace the mother page.
      // html: <div id="s2"> replace me </div> 
      $tim = time();
      document.getElementById("s2").innerHTML=$tim;
  }
}

/**
* @ajax_listen
* Timer to ping and pong
* Optional timer
*/
var tImer;
function ajax_listen(){
    ajax_connect(1,2,3,4);  
    cOunter=cOunter+1;
    tImer=setTimeout("ajax_listen()",1000);
}

 

 

Link to comment
Share on other sites

  • 2 weeks later...
  • 8 months later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.