1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
It does work in a similiar way but I have 2 problems at the moment.
Every Ajax "button" need its own function? currently it looks like that:
Code:
<script type="text/javascript">
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
function loadXMLDoc2()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","test.txt",true);
xmlhttp.send();
}
2 Functions with a different "GET", to display two different text files. Is there a proper way to display multiple files? I feel that having 2 huge functions where only the get request is different is a "waste"?
this adds #myNews to the URL for example "domain.com/#myNews"
but if I copy this url and send it to a friend he sees the usual homepage without the div called #myNews shown.
Any way to make this ajax content "bookmarkable" and that those URLs work?
the w3school doesnt offer much explanation and more examples
not necessarily... it would be better to modify the load function to accept parameters, and the parameter would be the file you want AJAX to GET. you'd replace that hardcoded "ajax_info.txt" or "text.txt" string with the variable you passed in as a parameter.
do you want the user to press one button to receive two files? if so, you'd have to make the AJAX load somewhat recursive, or you'd have to dispatch two AJAX requests at the same time.
this adds #myNews to the URL for example "domain.com/#myNews"
but if I copy this url and send it to a friend he sees the usual homepage without the div called #myNews shown.
Any way to make this ajax content "bookmarkable" and that those URLs work?
errr... there may be some confusion here..? that code above makes it so that if a user clicks that link, it will both fire the onclick event and then take the user to the "myNews" anchor on the page.
any element on a webpage (to my knowledge) can be anchored. it's up to you to ensure that the content in that element is populated when the anchor is called. beyond that, im not sure i understand what you want to do with this bookmark stuff.
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
I planned on making several buttons which all show different content just like on the page I posted above
(http://www.nukklear.com/)
when you trigger the AJAX function, id either pass the function a special variable to identify which file AJAX should get, or use the name of the button (the "this.name" property passed as an argument to your AJAX code) to identify the button that was clicked and retrieve the proper AJAX page.
This takes you to the website of nukklear with the content shown just like you have clicked the "The Team" button on top even though it is ajax
i didn't dig into the code, but they probably are just using the '#' sign instead of the '?' for accessing what are called "query strings". they parse the URL when the page loads, check for the # sign, and then AJAXally load the appropriate content based on whatever follows the # sign. actually, now that i think of it, it's brilliant.. you can still use the question mark to pass in "real" query strings...
anyway, it's a "faux" bookmark. the javascript does all the work.
1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.
i didn't dig into the code, but they probably are just using the '#' sign instead of the '?' for accessing what are called "query strings". they parse the URL when the page loads, check for the # sign, and then AJAXally load the appropriate content based on whatever follows the # sign. actually, now that i think of it, it's brilliant.. you can still use the question mark to pass in "real" query strings...
anyway, it's a "faux" bookmark. the javascript does all the work.
Thanks for that tip I will read into querystrings to find out how it works, if anyone however has a nice simple sample for it i'd appreciate
And the dynamic content is contained in HTML files (or ASP, PHP, etc.) named "Item1.html", "Item2.html", and "Item3.html"
And let's presume the dynamic area of your page is:
Code:
<div id="dynamicContent"></div>
Your AJAX function in jQuery is as simple as this:
Code:
function btnClick(theButton){
$('#dynamicContent').load(theButton.id + '.html')
}
This line of code:
theButton.id + '.html'
will be "theButton.id" which will be any of 'Item1', 'Item2', or 'Item3', concatenated with '.html', so you get "Item1.html", etc.
.load(), tells the page to load the page
$('#DynamicContent') tells it where to load it.
So you get
"set the contents of the DIV 'dynamicContent' to whatever is in the HTML page named the same as the ID of the button I just clicked".
Of course, you can rejigger this many different ways, and you don't need to use jQuery either... but the above should be enough of a working sample that you could use it to parameterize your AJAX call if you wish to do so.
Bookmarks