1

I want to be able to include a dynamic chunk of HTML in a page using javascript.

I wrote a servlet which returns a chunk of HTML, http://mydomain.com/dynamic.jsp It produces some HTML ( minus head, body tags ) like this:

<div>
     Current Weather : 89F
</div>

How can I get that dynamic chunk of HTML into the page using a line of Javascript?

What is the simplest way? I wonder if I need to wrap what the servlet produces in XML tags or in JSON format.

2 Answers 2

6

JQuery's .load() function is handy for loading data from a server, and you can dynamically put the HTML anywhere you want using the callback.

http://api.jquery.com/load/

Sign up to request clarification or add additional context in comments.

2 Comments

Note that this will only work if both scripts run on the same domain.
You are right, it works fantastic, except if I want to call a URL on another domain.
1

If you want to use prototypejs, take a look here: http://www.prototypejs.org/learn/introduction-to-ajax

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.