473,383 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ajax with servlet

I am trying to call a servlet i created. Basically this servlet
will let user create a new account at the server.
I have created the function "CreateAccount()" but
http_request.readyState always return me 0

What is wrong with my code?

function CreateAccount()
{
if( window.XMLHttpRequest )
{
http_request = new XMLHttpRequest();
}
else if( window.ActiveXObject )
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
var parameters = "username=" + encodeURI(
document.getElementById("username").value ) +
"&password=" + encodeURI(
document.getElementById("password").value );

http_request.onreadystatechange = RegisterUser();
http_request.open('post', "/servlet/CreateUserAccount", true );
http_request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);

}
}

function RegisterUser()
{
alert( "register user: " + http_request.readyState );
if( http_request.readyState == 4 )
{
if( http_request.status == 200 )
{
alert( http_request.responseText );
}
else
{

}
}
}

Dec 10 '05 #1
3 10915

Shinya Koizumi wrote:
http_request.onreadystatechange = RegisterUser();


You are assigning the return value of the function call to
RegisterUser(). You should be assigning a function reference instead:

http_request.onreadystatchange = RegisterUser;

Dec 10 '05 #2
Thanks it solved the previous problem
However, it takes about 10 seconds to get the response.
Do you happen to know why?
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

Shinya Koizumi wrote:
http_request.onreadystatechange = RegisterUser();


You are assigning the return value of the function call to
RegisterUser(). You should be assigning a function reference instead:

http_request.onreadystatchange = RegisterUser;

Dec 12 '05 #3
How long does it take to get a response if you call it
from an ordinary form, or browse to it manually?

--
Dag.

"Shinya" <xx*@smartestdesign.com> wrote in message
news:lcknf.159663$yS6.113623@clgrps12...
Thanks it solved the previous problem
However, it takes about 10 seconds to get the response.
Do you happen to know why?
"web.dev" <we********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...

Shinya Koizumi wrote:
> http_request.onreadystatechange = RegisterUser();


You are assigning the return value of the function call to
RegisterUser(). You should be assigning a function reference instead:

http_request.onreadystatchange = RegisterUser;


Dec 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Frances | last post by:
I literally started learning AJAX just last weekend.. I have this page, http://www.francesdelrio.com/ajax/db2.html, where I'm essentially doing what's here,...
1
nmm32
by: nmm32 | last post by:
I am trying to use Ajax with JSP to populate a 2nd drop down list based on the chosen option of the first one. I am getting the error "Object Expected" on the line 13-14 of the HTML: <script...
2
by: archanagp | last post by:
Hi, I am trying to develop a portlet which has a javascript function which uses ajax to call a servlet in the server. The portlet I am trying to develop is in websphere application developer. My...
6
by: santhoskumara | last post by:
How to request to servlet from Ajax and also I got the DOM object in the servlet through Business Logic. Now how will i pass the DOM object from serlvet to Clientside. Where in the client Side i am...
3
by: nnaveenraju | last post by:
Hi Gurus, I am new to Ajax and JAVA. I am able to call the servlet class from the JSP page using AJAX. The servlet class is called successfully. I am processing some data and the data has...
1
by: galdunne | last post by:
Hi, Im new to ajax and im using prototype for a project i am working on. I am hoping to call a servlet written in java which holds a hashtable to strings. When i click on a link it opens up a tab...
1
sid0404
by: sid0404 | last post by:
Hi I need to send data from my servlet to my html(which contains AJAX), so as per the motivation of the AJAX, this should be done without my webpage reloading / refresh. my code on the ajax...
3
by: rbansalit | last post by:
Hi all I am making a very simple ajax call. But I am not getting any message from sever. <html> <body> <script type="text/javascript"> function ajaxFunction()
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.