Loading object tag dynamically, via ajax

J

jon

I've got a page that uses a small set of ajax driven requests to
dynamically populate some divs on the page. It essentially takes the
responseText and puts it in myDiv.innerHTML where needed. Script
blocks are evaled already so they run.

I'm having trouble with a dynamic page contains an object tag that
pulls a .NET applet (IE only). Loading the object via traditional
html renders the control easily. However injecting it in the div
means it doesn't load.

<object id="myApplet" classid="/applets/Control.dll#Comp.Control"
height="200" width="200">
<param name="fields" value="one:two:three">
<param name="interval" value="1000">
</object>

Some things I've tried:
1) document.write() the object line by line within a script block, in
non-ajax situation. This renders the object okay. However
document.write() after the onload of the page clears the content so is
problematic w/ ajax after onload.
2) append the object to the dom with document.createElement('object')
within a script block, etc; it produces the object but it never loads
anything.


Any ideas how I can load the object via ajax? Or even simpler, how I
can dynamically load the object after page load?

Thanks
 
T

Thomas 'PointedEars' Lahn

jon said:
I'm having trouble with a dynamic page contains an object tag that
pulls a .NET applet (IE only). Loading the object via traditional
html renders the control easily. However injecting it in the div
means it doesn't load.

<object id="myApplet" classid="/applets/Control.dll#Comp.Control"
height="200" width="200">
<param name="fields" value="one:two:three">
<param name="interval" value="1000">
</object>

Some things I've tried:
1) document.write() the object line by line within a script block, in
non-ajax situation. This renders the object okay. However
document.write() after the onload of the page clears the content so is
problematic w/ ajax after onload.

Works as designed.
2) append the object to the dom with document.createElement('object')
within a script block, etc; it produces the object but it never loads
anything.

Any ideas how I can load the object via ajax?

Make an HTTP request. The response would have to include the HTML `object'
element, XML or JSON (or whatever data format that you find convenient).
You could then include the element's source code, or parse it, or include a
subtree of the XML document, or you could create the object from JSON (or
whatever) data.

http://developer.mozilla.org/en/docs/AJAX

(Contrary to what you might believe because of the domain, it contains
general information about the subject, not only Gecko-specific one.)
Or even simpler, how I can dynamically load the object after page load?

Document::createElement() is the right way. Anyhow, you have not posted any
line of your *script* code, so one can not even make an educated guess what
might go wrong.

http://www.jibbering.com/faq/faq_notes/clj_posts.html#ps1DontWork


PointedEars
 
J

jon

Document::createElement() is the right way. Anyhow, you have not posted any
line of your *script* code, so one can not even make an educated guess what
might go wrong.

Thanks for the thoughts so far. FYI-- the approximate code I'm using
to append the object to the dom via script is shown below. It fails
to work so far.

<body onload="loadObj()">
<script>
function loadObj(){
var obj = document.createElement("object");
obj.setAttribute("id","myApplet");
obj.setAttribute("classid","/applets/Control.dll#Comp.Control");
obj.setAttribute("height", "200");
obj.setAttribute("width", "200");

var param0 = document.createElement('param');
param0.setAttribute("name", "fields");
param0.setAttribute("value", "one:two:three");
obj.appendChild(param0);

var param1 = document.createElement('param');
param1.setAttribute("name", "interval");
param1.setAttribute("value", "1000");
obj.appendChild(param1);

document.body.appendChild(obj);
}
</script>
 
T

Thomas 'PointedEars' Lahn

jon said:
Thanks for the thoughts so far. FYI-- the approximate code I'm using
to append the object to the dom via script is shown below.

Approximate code does not really help with analyzing a script problem.
It fails to work so far.

"Does not work" is a useless error description. [psf 4.11]

Please read and take heed of the FAQ Notes entry I pointed you to already,
among others.
<body onload="loadObj()">
<script>

<script type="text/javascript">

And that code should be within the `head' element so that it is ensured it
available when the `load' event of the body element occurs.
function loadObj(){
var obj = document.createElement("object");

You should check whether or not document.createElement can be called.
Search the Google archive for "isMethodType".
obj.setAttribute("id","myApplet");

1. You should check once whether or not `obj' is an object reference,
before you use it:

if (obj)
{
// ...
}

2. Element::setAttribute() is known to be buggy in implementations.
Use element properties instead:

obj.id = "myApplet";
[...]
var param0 = document.createElement('param');
param0.setAttribute("name", "fields");
[...]
obj.appendChild(param1);

document.body.appendChild(obj);

Same here.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top