Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Ajax Includes Script - external instead of in Head?

  1. #1
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ajax Includes Script - external instead of in Head?

    Ajax Includes Script.
    http://www.dynamicdrive.com/dynamici...axincludes.htm

    Hi. I was wondering, would it be possible to use the Ajax Includes Script
    as an external file instead of it being repeated in the Head of each page?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Of course.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Heh, thanks. Maybe I should have added... how? I've spent a couple of hours experimenting with it but without any luck.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Just put the bit it says to paste into a seperate file - let's call it "ajax.js" - and include it where you would normally paste the script with the tag:
    Code:
    <script src="ajax.js" type="text/javascript"></script>
    This assumes that "ajax.js" is in the same directory as the page, of course.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hmm, the files I'm experimenting with are...

    Index.html
    Template.html
    ajax.js

    ...and they're all in the same directory. With the full script in the Head of the Index page it works great, but when the script is removed and replaced with a link to the external file the contents of the Template page are no longer included.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's strange... have you checked it's being included properly?
    Run
    Code:
    javascript:window.alert(typeof ajaxinclude == "function" ? "Script was included properly." : "Script wasn't included!");
    in the address bar of your browser whilst viewing your page.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That returns "Script wasn't included". It could just be that I'm overlooking something obvious.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I think it may be. Can you paste all your <head> section here (in [code] tags, please)?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Certainly...

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <HTML>
    
    <HEAD>
    
    <TITLE>Testpage</TITLE>
    
    <script src="ajax.js" type="text/javascript"></script>
      
    </HEAD>
    Viewed online, it gives an error:

    Line: 33
    Char: 13
    Error: Object Expected
    Code: 0

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Hm... nothing wrong there. You say it's live? Would you mind linking?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •