By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,706 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,706 IT Pros & Developers. It's quick & easy.

Help needed on JavaScript and Ajax..

P: 2
Hi All,
I have an requirement in my project, where i have to show a pop up with an moving icon when a button is clicked. But the problem is that the pop up should close automatically once we get the response from webservice. So i wanted to go with ajax as i far as my knowledge goes we also wanted asynchronous calls to the server side code to know whether the response has come or not.
I am using JSF and opening the pop from java code.Then I have a java script which calls the ajax function[to create objects -xmlHttpObject]. From the ajax function i am trying to call a servlet where i am actually writing the business logic.If the logic completes successfully without any exceptions that means the response is returned and i should get readyState as 4.Then i can do a self.close() in the ajax function to close the pop up. But unfortunately I dont know what is going wrong in this approach.

Some one please guide me. I need some suggestions so that i can implement it.
Feb 11 '07 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 15k+
P: 16,027
Welcome to The Scripts.

The method you have described should work fine. Please post your code (in code tags).
Feb 12 '07 #2

P: 2
Welcome to The Scripts.

The method you have described should work fine. Please post your code (in code tags).
Hi acorder,
Please find the code as followa :
1] My JSF page has a command button which has an action attribute and invokes a metod in the backing bean where I open a pop up.Please find the code to open pop up as follows -

String windowWidth = "575";
String windowHeight = "250";
html.append("<SCRIPT LANGUGE=\"JavaScript\">");
html.append("function windowOpen(){");
+ "'left=200,top=250,height="
+ windowHeight
+ ",width="
+ windowWidth
+ ",location=no,scrollbars=no,"
+ "menubars=no,toolbars=no,resizable=yes');");
html.append("<BODY onLoad=\"windowOpen()\">");
html.append("<form name=\"form2\">");

2] Now in the jsp - Sendrequest.jsp i do the following -

<SCRIPT language="javascript1.1">ajaxFunction()</SCRIPT>
function ajaxFunction()
{ var xmlHttp;
alert("in ajax function");
xmlHttp=new XMLHttpRequest(); }
catch (e)
{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e)
{ try
{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e)
{ alert("Your browser does not support AJAX!");
return false; } } }

alert("Before action methods");"GET","/RequestScopeServlet",true);
xmlHttp.onreadystatechange = callback;
alert("After action methods");


function callback() {
switch (xmlhttp.readyState){
case 1:
alert("Inside onLoading 1");
case 2:
alert("Inside onLoaded 2");
case 3:
alert("Inside onInteractive 3");
case 4:
alert("Inside Complete 4");



It should enter the forth Case and close the pop up. but my servlet is not invoked where i am executing my business methods.

Thanks in advance for any inputs on this.
Feb 13 '07 #3

Post your reply

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