View Full Version : Can we include JS Commands with AJAX include?
Yigit
08-19-2006, 11:14 AM
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 :o 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 :confused:
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
shachi
08-19-2006, 11:42 AM
well, try loading this, filename must be the same:
filename: script.php
echo 'alert("It works!!!")';
That's the only think that you can do.
Yigit
08-19-2006, 02:33 PM
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. :o
shachi
08-19-2006, 04:05 PM
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.
shachi
08-19-2006, 04:09 PM
I am not so sure about it but try using this:
filename: script.asp
response.write("alert('it works!!!')");
mwinter
08-19-2006, 04:25 PM
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
shachi
08-19-2006, 06:20 PM
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.
mwinter
08-19-2006, 06:56 PM
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
Yigit
08-19-2006, 10:38 PM
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:cool: . 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 :)
shachi
08-20-2006, 06:06 AM
Well then try this:
<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>
mwinter
08-20-2006, 08:51 PM
The reason why i want to use Ajax is that it looks cool.
Some uses of it might look cool, but AJAX itself is just a technology and doesn't look like anything.
It loads faster
Marginally; a second or two over even dial-up connections for well-written documents. It's not a justification for relying on it.
and people feel comfortable.
That's a dubious statement: the IXMLHTTPRequest interface is implemented in MSIE using ActiveX. Given the number of vulnerabilities that ActiveX has been responsible for over the years, you can't tell me that security-conscious people feel comfortable using it.
Disabling ActiveX disables AJAX.
People dont want to lose time between pages especially in my country where internet is slow.
Unless you frequently experience download rates of less than 3KB/s, you don't know the meaning of the word "slow".
You are also overlooking the fact of perceived speed: AJAX code waits until notification of a COMPLETED (4) ready-state change event. That is, they do nothing until the entire document has been received. A browser, on the other hand, will render a document as it receives it.
The structural overhead of a HTML document written with semantic markup in mind will amount to only a few kilobytes. It is the actual content that will account for the majority of the data. As I said earlier, a few kilobytes takes only a couple of seconds on even a dial-up modem (a tiny fraction of that over broadband), so arguing speed is just silly.
I agree that server side applications are better but just look at this site www.neseligunler.org
If I were really concerned about download speeds, the first thing I would want to do is disable images except for sites that actually need them. However, doing that here is impossible as the author hasn't bothered to provide alternative text for the navigation links. Moreover, by not specifying background colours, some of the text is unreadable without those background images. As a result, the user is required to download over 250KB of images.
It is a very easy ajax web site and it looks so sweet:cool:
It is a nice of example of graphic design, but it's poor as a Web site. The author sacrifices usability and compatibility simply so that AJAX could be used: there is no other explanation. Even then, the site could be implemented using both AJAX and a server-side fallback, but presumably the author wasn't competent enough for that.
As a result of the implementation choices, search engines cannot index content, users cannot bookmark specific pages, the site is useless for text browsers or assistive technologies, and unusable without scripting or ActiveX support (in MSIE).
If this site was created by different asp (or php) pages, i think it would be very bad...
Not at all. It would just transition between sections just like 99.9% of the other sites on the Web.
Mike
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.