Connection to server lost due to multiple ajax post requests

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: May 2008
Posts: 9
Reputation: poddarpallavi22 is an unknown quantity at this point 
Solved Threads: 0
poddarpallavi22 poddarpallavi22 is offline Offline
Newbie Poster

Connection to server lost due to multiple ajax post requests

 
0
  #1
Oct 14th, 2008
Hi
I am running an online examination system on intranet where a number of students appear for a test simultaneously. The paper contains only subjective questions and studens are provide a text area to fill in their answers. with each text area there is a "save answer" button which the student is supposed to click for saving that particular answer.
the answer is saved using ajax post method.

this is the code i use

var http = new ActiveXObject("Microsoft.XMLHTTP");
var params ="save="+save+"&s1="+ans+"&s2="+tot+"&s3="+y+"&s4="+n;
http.open('post', 'storeSubjective.jsp',false);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

the problem is that most of the times the student get disconnected from the url without any reason( even when the web server and the application are running)
if i use a different domain name then it works but not otherwise,
even on restarting the server the earlier url shows an error as if network connection is not there.
Has anyone come accross any such priblem befor?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 9
Reputation: poddarpallavi22 is an unknown quantity at this point 
Solved Threads: 0
poddarpallavi22 poddarpallavi22 is offline Offline
Newbie Poster

Re: Connection to server lost due to multiple ajax post requests

 
0
  #2
Oct 14th, 2008
actually "Internet Explorer cannot display the webpage " message comes.

my modem is fine, connection is fine, i can use other machines with the same connection & have no trouble accessing the web pages
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,614
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Connection to server lost due to multiple ajax post requests

 
0
  #3
Oct 14th, 2008
> if i use a different domain name then it works but not otherwise,

What do you mean by it works when using a different domain? Does using the complete URL instead of just 'storeSubject.jsp' seem to work? I can't think of any problems with code which might cause this issue; it either works or it doesn't. Do the web servers logs show anything?

> http.open('post', 'storeSubjective.jsp',false);

Why are you making synchronous calls? Do you really want to block till a response is returned from the server?

> http.setRequestHeader("Connection", "close");

Not necessary, drop it.

> http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

You have this yet you end up not encoding the data?
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 9
Reputation: poddarpallavi22 is an unknown quantity at this point 
Solved Threads: 0
poddarpallavi22 poddarpallavi22 is offline Offline
Newbie Poster

Re: Connection to server lost due to multiple ajax post requests

 
0
  #4
Oct 16th, 2008
first of all thanks a lot for your reply.

What do you mean by it works when using a different domain
ok. wht i mean here is that
http://12.245.234.15/storeSubjective.jsp does not work but
http://somedns/storeSubjective.jsp works
where somedns is the dns of the ip address 12.145.234.15.
this means the web server and the application are working.
infact on that machine even if i only switch the user the ip address url works.

also sometimes if initially the person logged on using http://somedns/storeSubjective.jsp
then this will stop working after some time but
http://12.245.234.15/storeSubjective.jsp this will continue working.

Why are you making synchronous calls? Do you really want to block till a response is returned from the server?
>> i am blocking till a reponse is returned because if the answers is not saved due to a server error i do not want the students to write further and waster their time.

> http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

You have this yet you end up not encoding the data?

>> wht do u mean by this?
i thought this line is for url encoding the data. i mean i want the students to be able to type "&" in their answers. this was not possible earlier when i was using GET request.
then i read more on ajax and discoverd that if i want to save very large data i should use POST instead GET.

i hope my problem is clear to you.
thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,614
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Connection to server lost due to multiple ajax post requests

 
0
  #5
Oct 16th, 2008
Your description here gives an indication that this might be a configuration / network issue rather than having something to do with Javascript as such.

> i am blocking till a reponse is returned because if the answers is not saved due to a
> server error i do not want the students to write further and waster their time.

And what happens when a server error occurs in your case? You anyways have to code a way around or handle the contingency be it synchronous / asynchronous calls. A better way would be to check the status of the asyn call and handle the different conditions accordingly.

> i thought this line is for url encoding the data. i mean i want the students to be able to
> type "&" in their answers. this was not possible earlier when i was using GET request.

Is it possible now? Are you able to send answers having characters '&', '=' and '?' ? Without an encoding in place for the user data, the answers would be sent as they are thereby causing unexpected effects at the server. Try it.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 9
Reputation: poddarpallavi22 is an unknown quantity at this point 
Solved Threads: 0
poddarpallavi22 poddarpallavi22 is offline Offline
Newbie Poster

Re: Connection to server lost due to multiple ajax post requests

 
0
  #6
Oct 20th, 2008
how should i write the code> i did not get you?
do u think my problem could be Internet explorer specific?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,614
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Connection to server lost due to multiple ajax post requests

 
0
  #7
Oct 21st, 2008
> var http = new ActiveXObject("Microsoft.XMLHTTP");

The way you create the XHR (XMLHttpRequest) object is IE specific and won't work on other browsers / operating systems. Use some Ajax library to ease your task.

> how should i write the code> i did not get you?

You need to encode the data you send to the server. Hence:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var params ="save="+save+"&s1="+ans+"&s2="+tot+"&s3="+y+"&s4="+n;
  2.  
  3. // the above needs to be replaced with
  4. var params ="save=" + encodeURIComponent(save) +
  5. "&s1=" + encodeURIComponent(ans) +
  6. "&s2=" + encodeURIComponent(tot) +
  7. "&s3=" + encodeURIComponent(y) +
  8. "&s4=" + encodeURIComponent(n);
...so that the data *really* is encoded.

> do u think my problem could be Internet explorer specific?

It surely isn't related to Javascript if that's what you want to know.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 9
Reputation: poddarpallavi22 is an unknown quantity at this point 
Solved Threads: 0
poddarpallavi22 poddarpallavi22 is offline Offline
Newbie Poster

Re: Connection to server lost due to multiple ajax post requests

 
0
  #8
Oct 23rd, 2008
even after doing the above changes my problem persists. i do not really know what to do?
actually this problem does not happen always so i can not even replicate it on my machine to test it on other browsers. i am now planning to conduct all exams on firefox. hopefully it may resolve my problem.
by the way could it be that my tomcat web server is denying page requested to that particular client?
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,160
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 531
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Connection to server lost due to multiple ajax post requests

 
0
  #9
Oct 23rd, 2008
it sounds like an error with your web server config.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,614
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 466
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Connection to server lost due to multiple ajax post requests

 
0
  #10
Oct 23rd, 2008
> even after doing the above changes my problem persists.

Like I have always mentioned in this thread, the intermittent problem isn't related to Javascript; it's just that I pointed out some mistakes and you fixed them.

> by the way could it be that my tomcat web server is denying page requested to that
> particular client?

Without any logs [application/tomcat], there is no way we can help you out. Get an expert to look at your network config / Tomcat installation.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC