aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes how to populate HTML div using AJAX to iterate and display arrayList values. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to populate HTML div using AJAX to iterate and display arrayList values." Watch "how to populate HTML div using AJAX to iterate and display arrayList values." New topic
Author

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

Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jan 10, 2002
Posts: 60999
    
  65

Is the JSON all that is displayed? None of your other HTML?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jan 10, 2002
Posts: 60999
    
  65

What does View Source show?
Monica. Shiralkar
Ranch Hand

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jan 10, 2002
Posts: 60999
    
  65

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

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jan 10, 2002
Posts: 60999
    
  65

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

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jul 07, 2012
Posts: 639
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

Joined: Jul 07, 2012
Posts: 639
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
 
jQuery in Action, 2nd edition
 
subject: how to populate HTML div using AJAX to iterate and display arrayList values.