Tuesday, September 11, 2012

PHP and AJAX interlocking




What is AJAX?

Describes the complex passes and gives a brief explanation of the ...
AJAX when any input entered in the form and send

Transfer is to wait until the end of all processing has been completed, no action does not

Cease transmission while we continue to work part or

Boredom is the method by which you can save as directing the progress of a blank page without seeing ...

For a simple example, look at

Access to our bulletin board, list more

Click to see the second page [2] that ...

At this time, which is usually a blank page or bring up a new page, look for the refresh (Refresh) the
We can see that the phenomenon ..

However, AJAX when all processing is complete, the result is passed in the current reporting

Discards the contents changed state ..

So do we not need to wait

However, this also may disadvantage a browser that does not support OS and any errors occur when

Disadvantage is that the time for that error, I can not grasp exactly ..

Hagoyo introduction here ^ ^

So How Will .. interlock

When using xmlHttpRequest can produce the light output of the input form page, which

Easy way to configure it, it does a lot ...

Let's look at a simple source ...

function createHttpRequest ()
{
 if (window.ActiveXObject) {
   / / Win e4, e5, e6 for
 
 try {
   return new ActiveXObject ("Msxml2.XMLHTTP");
      } Catch (e) {/ / # fails when part
      try {/ / here sy_narg ..
  return new ActiveXObject ("Microsoft.XMLHTTP");
      } Catch (e2) {/ / If the failure yimajeodo returns no value does not ..
     return null;
   }
 }
      }
      else if (window.XMLHttpRequest) {/ / other browser
 / / Win Max Linux m1, f1, o8, Mac s1 Linux k3 for
 return new XMLHttpRequest ();
      }
      else {
 return null;
      }
}
This function is tied to ..

These babies <script> and are available by calling </ script> between the need to ...

ajax = createHttpRequest (); / / in this way can be used to connect ...

However, you had to throw away such a use of Hangul because you're getting garbled when sending when to change to UTF-8

Work will be required ...

I've tied its function as part of ...

function sendRequest (callback, data, method, url, async, sload, user, password)
{
/ / Callback arguments if the value passed after the transfer means to handle ..
/ / Data required to deliver the data and paste that if you
/ / Method to select the manner POST or GET ...
/ / Url to specify the address to send and
/ / Async true if the asynchronous synchronous to false ..
/ / Sload the super-load can be used to force load (true) false or omitted.
/ / User and password to access if the authentication page by passing the argument is ..

 / / XMLHttpRequest object creation
 var oj = createHttpRequest ();
 if (oj == null) return null;
 / / Force load of settings
 var sload = (!! sendRequest.arguments [5])? sload: false;
 if (sload | | method.toUpperCase () == 'GET') url + = "?"; / / method is GET if? paste the address given data value to pass ..
 if (sload) url = url + "t =" + (new Date ()). getTime ();

oj.onreadystatechange = function ()
  {/ / If the value passed to the callback function, if one exists, will pass ...
   if (oj.readyState == 4) {/ / this part of the state are subject to the completion of the transfer, if ...
    callback (oj);
   }
  }

 / / URL encoding

 format in utf-8 format data = uriEncode (data); / / passing data, so there's value in Hangul ...
 if (method.toUpperCase () == 'GET') {
  url + = data;
 }
 oj.open (method, url, async, user, password); / / transmission is ...
 / / Set header application / x-www-form-urlencoded
 setEncHeader (oj) / / header set to the character set is set with ..

 / / Send method
 value oj.send (data); / / transfer data is transmitted .. If

 / / URI Encoding header set
 function setEncHeader (oj) {
  var contentTypeUrlenc = 'application / x-www-form-urlencoded; charset = UTF-8';
  if (! window.opera) {
   oj.setRequestHeader ('Content-Type', contentTypeUrlenc);
  } Else {
   if ((typeof oj.setRequestHeader) == 'function')
    oj.setRequestHeader ('Content-Type', contentTypeUrlenc);
  }
  return oj;
 }

 / / URL encoding

 function uriEncode (data) {
  if (data! = "") {
   / / = & And encode one decomposition

   var encdata ='';
   var datas = data.split ('&');
   for (i = 1; i <datas.length; i + +) {
    var dataq = datas [i]. split ('=');
    encdata + = '&' + encodeURIComponent (dataq [0]) + '=' + encodeURIComponent (dataq [1]);
   }
  } Else {
   encdata = "";
  }
  return encdata;
 }
  return oj;
}

AJAX introductory book entitled The reference source is ...

When you actually use onclick or link to sendRequest ("The callback function name", "data pass" will "transfer mode", "send", "yen Think", "super load"); formats ...

If the callback function onloadl

 function on_loadedl (oj) {
                var res = decodeURIComponent (oj.responseText);
                document.all.testview.innerHTML = res;
}
Use the value passed in this way, the output haejulsu We look ...

testview give output passed Div (layer) or if you specify the ID of the table values ​​or highs

No comments:

Post a Comment