|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic Ajax Content
I found an example of dynamic Ajax content on Dynamic Drive:
http://www.dynamicdrive.com/dynamic...ajaxcontent.htm Do you know if this example can be amended so that when a link is clicked the content in two DIV containers is changed? |
|
#2
|
||||
|
||||
|
There is a tutorial at AJAX freaks that shows how to change multiple dynamic divs. Tutorial
I have also done it by taking the response and splitting it (when I had control over the reponse coming in, so I knew that I could do it this way). Then I just set the innerHTML for the 2 divs to my split responses: Code:
function handleResponse() {
if(http.readyState == 4 && http.status == 200){
// Text returned FROM the PHP script
var response = http.responseText;
var split_response;
var loc_response = '';
var app_response = '';
if(response) {
//split response so we can update the 2 divs
split_response = response.split("*");
loc_response = split_response[0];
app_response = split_response[1];
alert(app_response);
// UPDATE ajaxTest content
document.getElementById("location").innerHTML = loc_response;
document.getElementById("applet").innerHTML = app_response;
}
}
}
__________________
|
|
#3
|
|||
|
|||
|
elkehinze - thanks again for your reply. I kinda see what your doing by splitting the response....just not sure how I go about making the necessary changes in the example on Dynamic Drive to do this?? My plan is to run this on a normal HTML page and I have no idea of PHP!!
|
|
#4
|
||||
|
||||
|
Check out that AJAX tutorial I showed you, they have lots of info, and there's other tutorials there too. You don't have to use PHP you could use another web language such as asp or jsp, I just happen to prefer PHP.
What you have to do is set up the php page (or whichver you use) to receive your variables that are passed from the functions to process. Here is my whole AJAX script below. I know it's hard to see what is coming in from location, but I was sending it a url from another page. Code:
//AJAX Script to refresh site information
function createRequestObject() {
var req;
if(window.XMLHttpRequest){
// Firefox, Safari, Opera...
req = new XMLHttpRequest();
} else if(window.ActiveXObject) {
// Internet Explorer 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
// There is an error creating the object,
// just as an old browser is being used.
alert('Problem creating the XMLHttpRequest object');
}
return req;
}
// Make the XMLHttpRequest object
var http = createRequestObject();
function sendRequest(loc) {
// Open PHP script for requests
http.open('get', 'speed.php?loc='+loc);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4 && http.status == 200){
// Text returned FROM the PHP script
var response = http.responseText;
var split_response;
var loc_response = '';
var app_response = '';
if(response) {
//split response so we can update the 2 divs
split_response = response.split("*");
loc_response = split_response[0];
app_response = split_response[1];
alert(app_response);
// UPDATE ajaxTest content
document.getElementById("location").innerHTML = loc_response;
document.getElementById("applet").innerHTML = app_response;
}
}
}
|
|
#5
|
|||
|
|||
|
Ok, I might have to study this in more detail so that I understand what is going on. Just one question, in this section of the code.....
Quote:
...I see how the response is split, but in what format are the variables coming in? Are the variables coming in a format like this - page.asp?var1=something&var2=somethingelse. |
|
#6
|
||||
|
||||
|
If you look at the sendRequest function above, it is receiving a var called loc, it then sends that var to speed.php and then returns the ouput of the processing at speed.php to handleResponse, so that's where it comes from.
You're partly right though, they are passed in variables. The loc var was submitted to the sendREquest function from a drop down combo box that called sendRequest onchange. |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > Dynamic Ajax Content |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|