AJAX

What is ajax synchronous and asynchronous?

Posted by om 7 July, 2010 (0) Comment

Synchronous – Script stops and waits for the server to send back a reply before continuing. There are some situations where Synchronous Ajax is mandatory.

In standard Web applications, the interaction between the customer and the server is synchronous. This means that one has to happen after the other. If a customer clicks a link, the request is sent to the server, which then sends the results back.

Because of the danger of a request getting lost and hanging the browser, synchronous javascript isn’t recommended for anything outside of (onbefore)unload event handlers, but if you need to hear back from the server before you can allow the user to navigate away from the page, synchronous Javascript isn’t just your best option.

Synchronous AJAX function Example using GET.

    function getFile(url) {
  if (window.XMLHttpRequest) {
    AJAX=new XMLHttpRequest();
  } else {
    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (AJAX) {
     AJAX.open("GET", url, false);
     AJAX.send(null);
     return AJAX.responseText;
  } else {
     return false;
  }
}
 
var fileFromServer = getFile('http://www.phpmind.com/om.txt');

Synchronous AJAX function Example using POST.

function getFile(url, passData) {
  if (window.XMLHttpRequest) {
    AJAX=new XMLHttpRequest();
  } else {
    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (AJAX) {
    AJAX.open("POST", url, false);
    AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    AJAX.send(passData);
    return AJAX.responseText;
  } else {
     return false;
  }
}
 
var fileFromServer = getFile('http://www.phpmind.com/data.php', sendThisDataAsAPost);

Asynchronous – Where the script allows the page to continue to be processed and will handle the reply if and when it arrives. If anything goes wrong in the request and/or transfer of the file, your program still has the ability to recognize the problem and recover from it.
Processing asynchronously avoids the delay while the retrieval from the server is taking place because your visitor can continue to interact with the web page and the requested information will be processed with the response updating the page as and when it arrives.

  • Share/Bookmark
Categories : AJAX Tags :

What is Ajax?

Posted by om 7 July, 2010 (0) Comment

Ajax (sometimes called Asynchronous JavaScript and XML) is a way of programming for the Web that gets rid of the hourglass. Data, content, and design are merged together into a seamless whole. When your customer clicks on something on an Ajax driven application, there is very little lag time. The page simply displays what they’re asking for.

Ajax is a way of developing Web applications that combines:

  • XHTML and CSS standards based presentation
  • Interaction with the page through the DOM
  • Data interchange with XML and XSLT
  • Asynchronous data retrieval with XMLHttpRequest
  • JavaScript to tie it all together
  • Share/Bookmark
Categories : AJAX Tags :

How to send bulk email through email software?

Posted by om 24 February, 2010 (2) Comment

If you’re sending an email campaign to thousands or millions of user using some software then you’re going to need a reliable mail server. Most of the shared servers are not going to allow you send more email. There are a lot of restrictions and host may impose email sending restrictions which makes it impossible to send.

There are ways to send –
1. You can send emails out application your web host’s mail sending engine. This advantage is accomplished if you’re sending only a few hundred emails per month, about as soon as you go over this, your host will not allow you to send more. This option is good for sending email using online php tools so many are available please check with google :)
2. You can buy your own committed server from service provider like RackSpace.com or netatlantic.com (we are using this!) and configure it to send emails. We send 60000 emails per month without any issue, they have easy to use web interface. We just create newsletter test and send to our subscribers. It works perfectly.

3. Most effective option is using third party mail server like SMTP.com. Even if you are using shared server you can use there service if you have tones of email to send. Don’t forget to negotiate for discount if you are using there partners software!!

  • Share/Bookmark
Categories : AJAX Tags :

How to delete a folder with PHP?

Posted by om 9 August, 2009 (0) Comment

To delete a file, or a folder and its contents i have compiled a recursive algorithm.
Hope this will be useful for all of you.

<?php
function rmdirr($dirname)
{
 
      // Sanity check
 
      if (!file_exists($dirname)) {
 
      return false;
 
      }
 
 
 
      // Simple delete for a file
 
      if (is_file($dirname) || is_link($dirname)) {
 
      return unlink($dirname);
 
      }       
 
      // Loop through the folder
 
      $dir = dir($dirname);
 
      while (false !== $entry = $dir->read()) {
 
      // Skip pointers
 
      if ($entry == '.' || $entry == '..') {
 
      continue;
 
      }
 
      // Recurse
      rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
 
      }
 
      // Clean up
      $dir->close();
 
      return rmdir($dirname);
 
      }
 
?>
  • Share/Bookmark
Categories : AJAX Tags :

How to get the page name of the current URL?

Posted by om 4 March, 2009 (0) Comment

Using this script you can get PHP current page from a url.

function CPageName() {
 return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

echo "The current page name is ".CPageName();
  • Share/Bookmark
Categories : AJAX Tags :