| | |
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
![]() |
•
•
Join Date: May 2008
Posts: 9
Reputation:
Solved Threads: 0
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?
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?
> 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?
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.
•
•
Join Date: May 2008
Posts: 9
Reputation:
Solved Threads: 0
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.
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.
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 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.
> 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: ...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.
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)
var params ="save="+save+"&s1="+ans+"&s2="+tot+"&s3="+y+"&s4="+n; // the above needs to be replaced with var params ="save=" + encodeURIComponent(save) + "&s1=" + encodeURIComponent(ans) + "&s2=" + encodeURIComponent(tot) + "&s3=" + encodeURIComponent(y) + "&s4=" + encodeURIComponent(n);
> 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.
•
•
Join Date: May 2008
Posts: 9
Reputation:
Solved Threads: 0
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?
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?
> 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.
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.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: 'Ajaxify'
- Next Thread: Value of radio-input
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column createrange() css cursor debugger dependent disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post problem programming progressbar regex runtime scroll search security select session shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n






