SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SCRIPT SRC tag not working from AJAX

    I have this piece of code:

    Code:
    <TABLE ID="weatherpane" BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="372" VALIGN="TOP" BGCOLOR="#475380">
    	<TR> 
    		<TD WIDTH="372" HEIGHT="43" CLASS="Basic_ARIAL_BLACK_EXTRALARGE" ALIGN="CENTER" STYLE="padding:20 0 0 0">The Weather
    		</TD>
    	</TR>
    	<TR>
    		<TD ALIGN="CENTER" STYLE="padding:8 0 20 0;">
    			<SCRIPT SRC='http://voap.weather.com/weather/oap/INXX0057?template=EVNTH&par=1005416873&unit=1&key=bfb3d15498a88172a8ed7720a38c102d'>
    			</SCRIPT> 
    		</TD>
    	</TR>
    </TABLE>
    which works by itself, but does not work when it comes into a div that is populated by AJAX. I tried the URL in the SCRIPT SRC tag by itself, and that works fine too. Does anyone know why this happens?

    Thank you very much for your time!

  2. #2
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    document.write() works when a page is being loaded. If the page is already loaded, document.write() tries to start a new document, clearing the document that is already there.
    It would be okay with an object that has its own document, e.g. a frame, an iframe or a new window.
    Does the weather service provide a version of the code that is not wrapped in document.write() ?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply, r51.

    Well, I would not think that the weather service provides such an alternative. However, I have been reading that innerHTML (that AJAX uses) does not execute scripts (i. e. javascript in this case). I think that is the problem here. Some people suggest that there are workarounds. Would you know of any?

    For the time being, I used an iframe (i. e. innerHTML now outputs an iframe) to load the table above, but that table is wrapped in a DIV (which I did not provide above) with an ID that my AJAX code populates with innerHTML.

    The frame works fine, but there are links in the table (which is inside the frame) that are AJAX links - i. e. when the links are clicked on, the original DIV's contents have to be updated. But the original DIV has this iframe loaded inside it, and any link which is an AJAX link will search for the DIV to send the innerHTML to inside the iframe (I think - I am yet to test that option). The code structure is like this:

    Code:
    <DIV id="ez">
    <iframe><!-- table above comes here --></iframe>
    </DIV>
    Would you have any ideas?

  4. #4
    SitePoint Evangelist
    Join Date
    Jul 2007
    Posts
    345
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you just give the iframe the id instead?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do not think so, since there are other pieces of code loading into the DIV (when other links are clicked on) that I do not want in iframes, since search engines do not crawl iframes...

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I solved the problem - it was not a pure solution that anyone else might be able to benefit from, but one specific to my case. Basically, I put just the part that had the SCRIPT SRC tag in an iframe, and so the innerHTML would output something like:

    Code:
    <table>
    something
    </table>
    <iframe>
    something
    </iframe>
    The point is, I could isolate the script src into an iframe because of the nature of my code here.

    Thanks, r51, for your time. Have a good day.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •