Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to populate HTML div using AJAX to iterate and display arrayList values.

 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Displayed where? The JavaScript you posted cannot produce that output.


It was displayed on the browser.The JSON was displayed in browser instead of just the parsed content. I suspect that the mistake is caused by the second line below:




If i do out.println(json) it is getting displayed as JSON, whereas I have written code in java script to parse json.

thanks

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the JSON all that is displayed? None of your other HTML?
 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. All I can see on the browser is below:



No HTML content my code would generate is seen on this browser.Probably some I am doing some basic mistake which I cannot figure out.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does View Source show?
 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On checking the 'view page source'( in google chrome), it shows the same:

[{"msg_id":"1","message":"hello"},{"msg_id":"12","message":"hello123"}]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That most likely means that your request to the servlet is not going through Ajax. The response is replacing the page in the browser.

How are you initiating the Ajax request?
 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making the AJAX call using Jquery. Below is the code I am using to make the ajax call:


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64633
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's really odd. Using the browsers developers' tools, set a breakpoint at the 1st statement of the success callback to see if the script is actually being executed correctly.
 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I am trying to isolate the issue using chrome debugger. I am getting a doubt that whether the issue is occurring because instead of servlet I am using a a struts Action.

A servlet has the below lines at end


whereas a struts action will have the below line at end

 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One confusing thing I have done is I am rendering response as it is.I think I should have a button and have all this AJAX job done on a button click or so.I will try that to isolate the issue.
 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done changes in code now and getting strange error in Chrome debugger stating "GET http://localhost:8080/SocialMediaSearch/pages/jquery-2.0.3.min.map 404 (Not Found) ".


I have just added a button on click of which the AJAX should be called.My code is :




It says GET http://localhost:8080/SocialMediaSearch/pages/jquery-2.0.3.min.map 404 (Not Found) but what is jquery-2.0.3.min.map. The jquery name is jquery-2.js then why is it expecting jquery-2.js.min.map.
 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I traversed this in both chrome debugger and eclipse debugger.

For javascript debugging I also used help of alert statements.

Observation for Javascript debugging:

It is reaching and printing alert message just before the below statement



In the code:







OBSERVATION from eclipse debugging:


After the javacript code line is called it goes inside the AJAXAction. But when it goes to below lines nothing happens:


After the above lines nothing happens in the below code:



thanks
 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To isolate the issue I have replaced struts action with servlet but still the issue persists.

Below is my Servlet code:



Below is ajaxExample.jsp


 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after debuging in Jchrome debugger and Eclipse it appears issue is from Struts side. From Jquery AJAX call it looks fine. So I have decided to now take help in Struts forum.

Thanks
 
Monica Shiralkar
Ranch Hand
Posts: 826
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since after click of button it is neither giving error in debugger not going inside eclipse debugger it appears issue is from Struts Action and struts xml config. I will try to resolve it from struts side.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic