472,328 Members | 1,550 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Ajax responses very slow.

Hi Friends,

I have a web application through which, the ajax is used to post the data onto the server and return the results. When i alert the xmlhttp.readystate sometimes it takes long time, that the process looks like freezing and sometimes its done very quickly as it is designed to.

I checked by alerting xmlhttp.readystate.

sometimes i get response 1,2 ,3 4 as the alert box quickly.
and sometimes i just get 1 and then nothing happens.

Has any one experienced the same.

Aug 24 '09 #1
10 7093
1,584 Expert 1GB
maybe problem with your PHP file. Try to send the same variables to the file through a manual call (enter it in your browser address bar), it maybe that this file never gets back.

Only thing I can think of that causes this.

Aug 24 '09 #2
Dheeraj Joshi
1,123 Expert 1GB
Just try to get the response from a dummy PHP file...

If the response time is same for every call.. then as dlite922 told its a problem with your PHP... Prpbably you need to fix some issues..

Dheeraj Joshi

I did not faced such problems.
Aug 25 '09 #3
I checked that , but if i send the variables directly to the php file as the action in the form tag, it goes out fine. I am using IE 7.0 and sometimes it works fine and sometimes does not work.
Aug 25 '09 #4
Dheeraj Joshi
1,123 Expert 1GB
Check it in FF(Fire Fox)... I got some problem when i used AJAX call in IE(Though not similar)...

Dheeraj Joshi
Aug 25 '09 #5
Hi Dheeraj,, even firefox and ie shows the same response. and there is a javascript code written that the web application cannot be used on a firefox. can you think of something else.
Aug 26 '09 #6
250 Expert 100+
Do think that multiple requests are being fired off?

If so, that may part of the bottleneck.

If I remember correctly, IE will open only 2 connections at once.

You might also want to add a timeout in your Ajax callback function so the application is more responsive.


Post your httpRequest and callback function.
Aug 26 '09 #7
5,390 Expert Mod 4TB
that seems more to be a problem with the JavaScript-code then with the php-code. could you post the JavaScript-code that is relevant for the ajax-call?

kind regards
Aug 26 '09 #8
Dheeraj Joshi
1,123 Expert 1GB
Ok.... I dont know any other solution.

Just post the Java script like GITS told... It may be the culprit....

Dheeraj Joshi
Aug 26 '09 #9
Thank you for your reply.

I dont know to check if the multiple requests are being fired off.can you pls provide detail on it.
Aug 27 '09 #10
First i was using the following codes:-

The function is called on submit of a button.

Expand|Select|Wrap|Line Numbers
  1. function submitform()
  2. {
  3. result=0;
  4. //gettting the form values;
  5. var requestid=document.getElementById("requestid").value;
  6. var sdenggname=document.getElementById("sdenggname").value;
  7. var sla=document.getElementById("sla").value;
  8. var helpdesk_comments=document.getElementById("helpdesk_comments").value;
  9. var calltype=document.getElementById("calltype").value;
  10. //validation part
  11. if(sdenggname=="--"||sla=="--"||helpdesk_comments==""||calltype=="--")
  12. {
  13. alert("Please make sure that you have filled in all the fields");
  14. return false;
  15. }
  16. //validateion part end
  17. var domain=document.domain;
  19. var url = "http://"+domain+"/crfportal/assignhelpdeskcalls_submit.php"; //url
  21. var params = "requestid="+requestid+"&sdenggname="+sdenggname+"&sla="+sla+"&helpdesk_comments="+helpdesk_comments+"&calltype="+calltype; //generating parameters
  23. //displaying the user with a statment while the request is being sent.
  24. document.getElementById("d1").innerHTML="<table><tr><td>Please wait while the call is getting assigned</Td></tr></table>"
  25. var xmlhttp=false;
  26. //alert(params);
  27. /*@cc_on @*/
  28. /*@if (@_jscript_version >= 5)
  29. // JScript gives us Conditional compilation, we can cope with old IE versions.
  30. // and security blocked creation of the objects.
  31.  try {
  32.   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  33.  } catch (e) {
  34.   try {
  35.    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  36.   } catch (E) {
  37.    xmlhttp = false;
  38.   }
  39.  }
  40. @end @*/
  41. if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  42.     try {
  43.         xmlhttp = new XMLHttpRequest();
  44.     } catch (e) {
  45.         xmlhttp=false;
  46.     }
  47. }
  48. if (!xmlhttp && window.createRequest) {
  49.     try {
  50.         xmlhttp = window.createRequest();
  51.     } catch (e) {
  52.         xmlhttp=false;
  53.     }
  54. }
  55.       //alert("xmlhttp"+xmlhttp);
  56.  try{xmlhttp.open("POST", url, true);}
  57.  catch(e)
  58.  {
  59.       alert("some error");
  60. }
  62. //Send the proper header information along with the request
  63. xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  64. xmlhttp.setRequestHeader("Content-length", params.length);
  65. xmlhttp.setRequestHeader("Connection", "close");
  67. xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
  69.     if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  71.         result=xmlhttp.responseText;
  72.         if(result!=0)
  73.         {
  74.         window.location="assignsdcalls.php?refresh=1";
  75.         }
  76.     }
  77. }
  78. xmlhttp.send(params);
  79. }

Then i changed the above code to the following:

Expand|Select|Wrap|Line Numbers
  1. function submitform()
  2. {
  3. result=0;
  4. //gettting the form values;
  5. var requestid=document.getElementById("requestid").value;
  6. var sdenggname=document.getElementById("sdenggname").value;
  7. var sla=document.getElementById("sla").value;
  8. var helpdesk_comments=document.getElementById("helpdesk_comments").value;
  9. var calltype=document.getElementById("calltype").value;
  10. var status=document.getElementById("reqstatus").value;
  11. var sdenggcomment=document.getElementById("sdenngcomments").value;
  12. //document.form1.submit();
  13. //validation part
  14. if((status=='Closed'||status=='closed')&& sdenggcomment=="")
  15. {
  16. alert("The call under closed status need to have comment")
  17. return false;      
  18. }
  19. if(sdenggname=="--"||sla=="--"||helpdesk_comments==""||calltype=="--")
  20. {
  21. alert("Please make sure that you have filled in all the fields");
  22. return false;
  23. }
  24. //validateion part end
  25. //setTimeout("",1250);
  26. document.getElementById("assigncall").disabled=true;
  27. var domain=document.domain;
  29. var url = "http://"+domain+"/crfportal/assignhelpdeskcalls_submit.php"; //url
  30. //var url1 = ""; //url to be used when the is there.
  31. var params = "requestid="+requestid+"&sdenggname="+sdenggname+"&sla="+sla+"&helpdesk_comments="+helpdesk_comments+"&calltype="+calltype+"&status="+status+"&sdenggcomment="+sdenggcomment+ "&rand=" + (new Date()); //generating parameters
  32. document.getElementById("d1").innerHTML="<table><tr><td>Please wait while the call is getting assigned</Td></tr></table>"
  33. var xmlhttp=false;
  34. xmlhttp=new ajaxRequest();
  35.  try{xmlhttp.open("POST", url, true);}
  36.  catch(e)
  37.  {
  38. try{xmlhttp.open("POST", url1, true);}
  39. catch (e)
  40.      {
  41.       alert("some error");}
  42.  }
  44. //Send the proper header information along with the request
  45. xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  46. //xmlhttp.setRequestHeader("Content-length", params.length);
  47. //xmlhttp.setRequestHeader("Connection", "close");
  49. xmlhttp.onreadystatechange = function() {//Call a function when the state changes.
  50. //alert(xmlhttp.readyState);
  52.     if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  53.         result=xmlhttp.responseText;
  54.         if(result!=0)
  55.         {
  56.         //document.getElementById("d1").innerHTML="<table><tr><td>"+result+"</Td><td><a href='assignsdcalls.php'>Assign another calls</a></td></tr></table>";
  57. //document.getElementById("assigncall").disabled=true;
  58. window.location="assignsdcalls.php?refresh=1";
  59.         }
  60.     }
  61. }
  62. xmlhttp.send(params);
  64. }
The function ajaxrequest is defined as follows:-

Expand|Select|Wrap|Line Numbers
  1. function ajaxRequest(){
  2.  var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
  3.  if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  4.   for (var i=0; i<activexmodes.length; i++){
  5.    try{
  6.     return new ActiveXObject(activexmodes[i])
  7.    }
  8.    catch(e){
  9.     //suppress error
  10.    }
  11.   }
  12.  }
  13.  else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  14.   return new XMLHttpRequest()
  15.  else
  16.   return false
  17. }
when i give alert on xmlhttp.readystate sometimes i get alert as 1234 very quickly and sometimes it just stops after 1.

Also after going through my code, if you see any thing which is not a good programming practice. please let me know.
Aug 27 '09 #11

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

Similar topics

by: Trip | last post by:
Please if someone can help me !!! I need client and server code(principle based on AJAX) for next problem: i have 3 <select> tags on html...
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to...
by: petermichaux | last post by:
Hi, Is it possible for an AJAX request to be left open for multiple responses? This could avoid repetitive polling of the server. Thanks,...
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is...
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM...
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
by: simon | last post by:
hello, I have a server set up on my local (home) network and can not get an ajax application to run on the box. it works fine on our...
by: zalek | last post by:
I am writing application with Ajax in sync mode - xmlHttp.open("GET", url, false). I noticed that in FireFox handler doesn't starts. It starts when...
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.