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

Thread: Can we include JS Commands with AJAX include?

  1. #1
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can we include JS Commands with AJAX include?

    Hi everybody, i newly discovered this site and i learned many things. Thank you all

    I created dynamic pages using "Dynamic Ajax Content" sample. I am used with ASP and it works GREAT But
    The page i want to include contains javascript fonctions. In fact it is the Switch Content Script that i use in included pages. But the script doesnt work when it is included by ajax
    I put the javascript code between main page's <head> section; it didn't worked.
    Then I put it in the include page's <head> section; it didn't worked.
    Lastly i created a js document, i pasted the code there. And i linked
    javascript:ajaxpage('test.htm', 'contentarea'); loadobjs('javascript.js')"

    But it didnt worked.

    I searched all the google but i coudn't learn how to use include js used pages with ajax

    Is it impossible?
    Thank you

  2. #2
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    well, try loading this, filename must be the same:

    filename: script.php
    Code:
    echo 'alert("It works!!!")';
    That's the only think that you can do.

  3. #3
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much for your fast response ;=)

    You wrote an php code. I use ASP but i transformed it to asp. I liked your advise; I must start from simple code But even i coudn't call the sample code :/ I tried to include via javascript and it works. So the js file is working. BUT the ajax include code doesnt work.

    I am searching the point where i made the mistake and i will share with you

    Have a great day.

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I am sorry but I don't think that I can help you with ASP. I am a complete worse than a noob in ASP. Actually I never coded in ASP.

  5. #5
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I am not so sure about it but try using this:

    filename: script.asp

    Code:
    response.write("alert('it works!!!')");

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Yigit
    I created dynamic pages using "Dynamic Ajax Content" sample. I am used with ASP and it works GREAT ...
    If you have a server-side language like ASP available, why use something as unreliable as AJAX, then?

    Client-side scripting can be a great addition to a document or a site, but "addition" is the operative word: don't rely on it, especially if you don't need to.

    Mike

  7. #7
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mwinter
    If you have a server-side language like ASP available, why use something as unreliable as AJAX, then?
    An appropriate answer to this would be that people want to display there pages dynamic without page reloads. They want their users to have a feeling of desktop applications.

    But it is good to use any server side language than using client side.

  8. #8
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by shachi
    An appropriate answer to this would be that people want to display there pages dynamic without page reloads.
    If they must (and there's little reason to), they can use frames.

    They want their users to have a feeling of desktop applications.
    Web applications can use client-side scripting to improve the interface, but it's not a substitute for using the server, only an addition. Most uses of AJAX fail to take this into consideration (Gmail didn't, for example, when it was first released, and wouldn't work in many browsers).

    Mike

  9. #9
    Join Date
    Aug 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi;
    I use usually ASP. The reason why i want to use Ajax is that it looks cool. It loads faster and people feel comfortable. People dont want to lose time between pages especially in my country where internet is slow.

    I agree that server side applications are better but just look at this site www.neseligunler.org It is a very easy ajax web site and it looks so sweet . It is turkish but you can understand the design. If this site was created by different asp (or php) pages, i think it would be very bad...

    But i still cannot include javascript used pages lol... I am trying

  10. #10
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well then try this:

    Code:
    <script type="text/javascript">
    
    /***********************************************
    * Ajax Includes script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
    ***********************************************/
    
    //To include a page, invoke ajaxinclude("afile.htm") in the BODY of page
    //Included file MUST be from the same domain as the page displaying it.
    
    var rootdomain="http://"+window.location.hostname
    
    function ajaxinclude(url) {
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
    page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
    try {
    page_request = new ActiveXObject("Msxml2.XMLHTTP")
    } 
    catch (e){
    try{
    page_request = new ActiveXObject("Microsoft.XMLHTTP")
    }
    catch (e){}
    }
    }
    else
    return false
    page_request.open('GET', url, false) //get page synchronously 
    page_request.send(null)
    writecontent(page_request)
    }
    
    function writecontent(page_request){
    if (window.location.href.indexOf("http")==-1 || page_request.status==200)
    eval(page_request.responseText)
    }
    
    </script>

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
  •