| Author |
Problem with Ajax
|
Prashant Langade
Ranch Hand
Joined: Jul 01, 2009
Posts: 70
|
|
Hi
My requirement is to get the list of account views based on some operatorId.I am using ajax to achieve this.
Front end is Struts.
Now I am able to give ajax call with out any problem.but when i get the list of string values from the database into the action class, i am not able to see them.
Here is a some code.
Now i want to get that alert (in bold) work, (i.e from action class,the list of values should be get shown by that alert,which i am not able to see.
Can any one please help me on this?
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
Well if the request is being made and the alert is being called. I am guessing your problem will be with: accountView.do?operatorSid="+operatorSid
What are you doing on the serverside to return data back to the client?
Eric
|
 |
Prashant Langade
Ranch Hand
Joined: Jul 01, 2009
Posts: 70
|
|
Hi Eric
Thanks for your time and quick reply.
Alert is not getting called..
Now if i put some alert.say alert("Hi"); just before the alert(xmlhttp.responseText);
then it gets called,but alert(xmlhttp.responseText); is not getting executed. basically i want to get the server side contents which are returned back from action class in the javascript.
I guess i need to set some response type or some thing like that kind of stuff in the action class after getting the list..
This is my action class
|
 |
Prashant Langade
Ranch Hand
Joined: Jul 01, 2009
Posts: 70
|
|
Iterator ite = accountViewsStatusResponse.getAccountViewsList().iterator();
while(ite.hasNext()) {
Object obj = ite.next();
AccountOperatorExtract accountOperatorExtract = (AccountOperatorExtract) obj;
System.out.println("Account Views: "+accountOperatorExtract.getAccountView());
}
The line accountViewsStatusResponse.getAccountViewsList() returns me the list of the views.
Am i missing any thing in order to send it back to javascript function?
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
Have you checked the status code? Is it 200 or is it an error. You should not rely just on readyState of 4.
Eric
|
 |
Prashant Langade
Ranch Hand
Joined: Jul 01, 2009
Posts: 70
|
|
Hi Eric
I checked the status..I am getting it as 500.
I still dont understand.how do i transfer values that i am getting in action(.java class) to javascript...
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
500 means you have an issue on your server.
Check your error logs and see what your serverside error is.
Eric
|
 |
Prashant Langade
Ranch Hand
Joined: Jul 01, 2009
Posts: 70
|
|
Hi Eric
Thanks for your solution..i checked the log and then i resolved it.
Actually i was forwarding the request to wrong jsp. no for testing purpose i created the blank.jsp and forwarded the request to that jsp.
now i am able to get the status code as 200. but when i wanted to check the returned list from the server in the function,i am getting it blank.
Here is what i did in my javascript function
alert(xmlHttp.responseText);
using this alert i am trying to read the response,but i am getting it as blank.
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15357
|
|
When you look at it on your test page which you resolved the 500 error with, are you seeing any output?
Eric
|
 |
Prashant Langade
Ranch Hand
Joined: Jul 01, 2009
Posts: 70
|
|
No.. since I had forwarded my request to blank.jsp. which contains nothing.
return mapping.findForward("success");
this is forwarding my request to blank.jsp
earlier when i was getting 500 error code ,that time i was forwarding my request to some other jsp had some code which required some parameters/values from the action class.
After i forwarded my request to blank.jsp .i started getting the status code as 200. and since the jsp is blank,i can not see any output.
|
 |
Prashant Langade
Ranch Hand
Joined: Jul 01, 2009
Posts: 70
|
|
Hi Eric,
I was able to resolve the issue by adding the following lines in the action class in the end
response.setContentType("text");
response.getWriter().write("Data to be passed";
response.getWriter().flush();
Thanks for your time and efforts Eric!!
Prashant
|
 |
Prashant Langade
Ranch Hand
Joined: Jul 01, 2009
Posts: 70
|
|
Hi..
After this issue got resolved,i am facing a problem.
Actually my requirement is this that i need to place the list of account views coming from xmlHttp.responseText in a dropdown(i.e populate a dropdown).
So i tried sending response from my action class to javascript function as (i.e if the account view list contains 3 values IA,FA,GA,then
I am creating a HTML select structure dynamically in action class and sending it to javascript function)
so my response (i.e xmlHttp.responseText looks like
<select>
<option>IA</option>
<option>FA</option>
<option>GA</option>
</select>
In order to populate the dropdown,in my JSP ,i have created a div like this
<td id="" >
<div id="drpdwndiv">
</div>
</td>
and in my javascript function where i am getting the response,I am trying to set the structure of select box in the form of response by
document.getElementById("drpdwndiv").innerHTML=xmlhttp.responseText;
.
but some how it is not getting executed.the alert("set") is not getting executed.
can any one please help me?
|
 |
Prashant Langade
Ranch Hand
Joined: Jul 01, 2009
Posts: 70
|
|
hey..
Solved the problem
Thanks and Regards
Prashant
|
 |
 |
|
|
subject: Problem with Ajax
|
|
|