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

acoder
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("<HTML>");
html.append("<TITLE></TITLE>");
html.append("<HEAD>");
html.append("<SCRIPT LANGUGE=\"JavaScript\">");
html.append("function windowOpen(){");
html.append("window.open('/web-swaf/faces/steel247/dh/jspf/Sendrequest.jsp','RequestScope',"
+ "'left=200,top=250,height="
+ windowHeight
+ ",width="
+ windowWidth
+ ",location=no,scrollbars=no,"
+ "menubars=no,toolbars=no,resizable=yes');");
html.append("form2.submit();");
html.append("}");
html.append("</SCRIPT>");
html.append("</HEAD>");
html.append("<BODY onLoad=\"windowOpen()\">");
html.append("<form name=\"form2\">");
html.append("</form>");
html.append("</BODY>");
html.append("</HTML>");

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

<SCRIPT language="javascript1.1">ajaxFunction()</SCRIPT>
<SCRIPT>
function ajaxFunction()
{ var xmlHttp;
alert("in ajax function");
try
{
xmlHttp=new XMLHttpRequest(); }
catch (e)
{
try
{ 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");
xmlHttp.open("GET","/RequestScopeServlet",true);
xmlHttp.onreadystatechange = callback;
xmlHttp.send(null);
alert("After action methods");

}

function callback() {
switch (xmlhttp.readyState){
case 1:
alert("Inside onLoading 1");
break;
case 2:
alert("Inside onLoaded 2");
break;
case 3:
alert("Inside onInteractive 3");
break;
case 4:
this.parent.refresh();
alert("Inside Complete 4");
me.close();
break;

}

}
</SCRIPT>

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.