By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,647 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,647 IT Pros & Developers. It's quick & easy.

Ajax speed problem

P: 2
Hi All,

Ive been having a problem of late with one of my sites that uses PHP5 / Ajax. The problem is that periodically the ajax functions lock up and it gets stuck in the loading phase of the request. If i restart the apache server everything goes back to normal (i assume it severs the connection to the ajax called function).

I think this is a problem with the javascript part as i have tried it using a straight post request and have have no problems and slow loading time is localized to the one user (ie. still works fine on the other computers on my office network).

I have recorded this happening in Firefox, safari and IE6 & 7

My server is running debian with apache2 and php5

Just wondering if somebody can shed some light on what my problem may be?


Cheers

Will
Oct 15 '07 #1
Share this Question
Share on Google+
2 Replies


dmjpro
100+
P: 2,476
Hi All,

Ive been having a problem of late with one of my sites that uses PHP5 / Ajax. The problem is that periodically the ajax functions lock up and it gets stuck in the loading phase of the request. If i restart the apache server everything goes back to normal (i assume it severs the connection to the ajax called function).

I think this is a problem with the javascript part as i have tried it using a straight post request and have have no problems and slow loading time is localized to the one user (ie. still works fine on the other computers on my office network).

I have recorded this happening in Firefox, safari and IE6 & 7

My server is running debian with apache2 and php5

Just wondering if somebody can shed some light on what my problem may be?


Cheers

Will
Ok post your codes here with Code Tags.
And let us know it.

Debasis Jana
Oct 15 '07 #2

P: 2
Ok post your codes here with Code Tags.
And let us know it.

Debasis Jana
Hi,

Here is my main ajax function

Cheers

Will


Expand|Select|Wrap|Line Numbers
  1.  
  2. function submitFormCustom(f, field1, field2, dable){     
  3.     // disable form, or not
  4.     disable = true;
  5.     lastform = f;
  6.     if (disable === true) {
  7.         disable_form(f, true);
  8.     }
  9.  
  10.     // re-id eval ajax part
  11.     if (document.getElementById('ajxjs')) {    
  12.         document.getElementById('ajxjs').innerHTML = '';
  13.         document.getElementById('ajxjs').id = 'id_'+Math.random();
  14.     }
  15.  
  16.  
  17.     if(window.XMLHttpRequest){ 
  18.         var xmlReq = new XMLHttpRequest(); 
  19.  
  20.         if (xmlReq.overrideMimeType) {
  21.             //set type accordingly to anticipated content type
  22.             //http_request.overrideMimeType('text/xml');
  23.             xmlReq.overrideMimeType('text/html');
  24.         }
  25.     } else if(window.ActiveXObject) { 
  26.  
  27.         try {
  28.             var xmlReq = new ActiveXObject("Msxml2.XMLHTTP");
  29.         } catch (e) {
  30.             try {
  31.                 var xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
  32.             } catch (e) {}        
  33.         }
  34.     } 
  35.  
  36.     var formData = '', elem = ''; 
  37.     for(var s=0; s<f.elements.length; s++){ 
  38.         elem = f.elements[s]; 
  39.         if ((elem.type == 'checkbox' || elem.type == 'radio') && elem.checked == false) {
  40.             continue;
  41.         }
  42.  
  43.         var selemval = '';
  44.  
  45.         if (elem.tagName == 'SELECT' && elem.multiple === true) {
  46.             var selem = elem.getElementsByTagName('option');
  47.             for (i = 0; i < selem.length; i++) {
  48.                 selemval = '';
  49.                 if (selem[i].value != "" && selem[i].selected === true) {
  50.                     if(formData != ''){ 
  51.                         formData += '&'; 
  52.                     } 
  53.                     selemval = selem[i].value; 
  54.                     formData += elem.name+"="+selemval.replace(/&/g, 'amp;'); 
  55.                 }
  56.             }
  57.         } else {
  58.             if(formData != ''){ 
  59.                 formData += '&'; 
  60.             } 
  61.             selemval = elem.value;
  62.             formData += elem.name+"="+selemval.replace(/&/g, 'amp;');
  63.         }
  64.     } 
  65.  
  66.     if (formData != "") {
  67.         formData += "&xrand="+randomString(8);
  68.     }
  69.  
  70.  
  71.  
  72.     xmlReq.onreadystatechange = function(){ 
  73.         if(xmlReq.readyState == 4){ 
  74.  
  75.             if (content = xmlReq.responseText) {
  76.  
  77.                 if (trim_str(content) != "") {
  78.                     try {
  79.                         document.getElementById(field1).innerHTML = content;
  80.                     }
  81.                     catch (e) {
  82.                         alert(document.getElementById(field1).innerHTML);
  83.                     }
  84.                     // evaluate JSON
  85.                     if (document.getElementById('jsonjs')) {
  86.                         try {
  87.                             var json = eval("(" + document.getElementById('jsonjs').innerHTML + ")");    
  88.                         } catch (e) {
  89.                             alert('Could not evaluate JSON '+e);
  90.                         }
  91.                     } // end eval JSON
  92.                     // evaluate regular JS
  93.                     if (document.getElementById('ajxjs')) {
  94.                         try {
  95.                             eval(document.getElementById('ajxjs').innerHTML);    
  96.                         }
  97.                         catch (e) {
  98.                             alert('Could not evaluate javascript '+e);
  99.                         }
  100.                     } // end eval js
  101.                     if (disable === true) {
  102.  
  103.                         if (!document.getElementById('msgdivarea') && !document.getElementById('cbform')) {
  104.                             disable_form(f, false);
  105.                         }
  106.  
  107.                         if (resetform === true){
  108.                             f.reset();
  109.                         }
  110.                     }
  111.                 }
  112.             }
  113.             document.getElementById(field2).innerHTML = "";
  114.             blockoff = false;
  115.         } else if (xmlReq.readyState == 1) {
  116.             document.getElementById(field2).innerHTML = '<span class="ld">Loading ...</span>';
  117.         } else if (xmlReq.readyState == 3) {
  118.             document.getElementById(field2).innerHTML = '<span class="ld">Please wait ...</span>';
  119.         } else if (xmlReq.readyState == 2) {
  120.             document.getElementById(field2).innerHTML = "";
  121.         }
  122.     }
  123.     xmlReq.open(f.method, f.action, true);
  124.     xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  125.     xmlReq.setRequestHeader("Content-length", formData.length);
  126.     xmlReq.setRequestHeader("Connection", "close");
  127.     xmlReq.send(formData); 
  128.     return false; 
  129.  
  130. }
  131.  
Oct 15 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.