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?

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

> 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?

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.

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.

how should i write the code> i did not get you?
do u think my problem could be Internet explorer specific?

> 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:

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);

...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.

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?

it sounds like an error with your web server config.

> 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.

is it the Anti DOS features?

I know that some web servers have features to stop a lot of people posting at once in order to stop DDoS attacks

What kind of logs are we talking of?
If you can give me some lead may be i can look at the logs my self and try to find out the problem.

The logs generated by your web server and your application.

Assuming you are using a logging library, your application should generate some kind of logs when it runs. E.g. when an exception is encountered, where do you see its exception trace?

Also, in case of Apache Tomcat, a servlet container, the logs are generated at <TOMCAT_HOME>\logs.

Ajax applications generally don't function as expected when different domain names are used, eg. simply forgetting a 'www' in the URL can screw things up.

SoniaBaby

Guys i have still not been able to solve my problem. but i am pretty convinced now that nothing is wrong with my web server configuration.
Could it be possible that the browser does not connect to the server because of the long length of POST parameters. is there any browser specific constraint on post requests made through ajax? for that matter is there any difference between ajax POST request and a normal form POST request.

its 255 chars isnt it?

no the request is much more more than 255 chars.
the code is as follows :

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");


where ans could be upto 10000 charecters

any suggestions?

> its 255 chars isnt it?

No, it isn't.

> where ans could be upto 10000 charecters

I have been successful in sending more than 33,000 characters when posting data [Tomcat 6.0] both asynchronously and synchronously using both IE and Firefox.

So like I had previously mentioned, there is something definitely wrong with your configuration or code and not anything related to GET or POST limit.

If you don't have time to change your server configs, why don't you try sending the requests in a staggered manner, one at a time. Each request's callback can initiate the next request in the sequence, which would mean your server only has to respond to one request at a time.

The number of requests is not the issue here; after all, web servers are tailored to handle several concurrent requests simultaneously.

The only issue i saw here is that, Mr. poddarpallavi22 is not giving us the log traces.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.