Jump to content

Recommended Posts

I would love to find an elegant way to do the following sequence. I'm so new to PHP that its easier to ask because I don't know what to look for.

 

Lets say I have the following files.

 

index.php

my_javascript.js

 

The index file calls my Javascript in the normal fashion with the following code.

<script src="my_javascript.js" type="text/javascript"></script>

 

In my JS file there is a section which dynamically adds content to a <div> that is in the index.php file. I must use the JS file to add the content.

 

HERE IS MY PROBLEM.

 

How do I dynamically replace the content in the JS file BEFORE it gets sent to the user?

 

EXAMPLE of index.php:


<html>
<head>

<script src="my_javascript.js" type="text/javascript"></script>

</head>
<body>

<div id="my_id"> This is static text that will be dynamically changed by Javascript. </div>

</body>
</html>

 

EXAMPLE of my_javascript.js:


replace_contents += 'This is the dynamic content of the div to be changed.';

 

So, I need to replace the line "This is the dynamic content of the div to be changed." with something from a php array before it gets sent to the user.

 

Thanks for your help.

Ok. That seems logical. I hadn't played with AJAX yet but I looked up some basics.

 

I have a few Q's though about the process. Is this correct?

 

1) Server side scripts are run

2) Client data is sent

3) Web App (Firefox ect) displays client data and runs client side scripts.

4) User generates query and AJAX requests data.

5) Changed data is displayed.

 

So, if I were creating a gallery and the user clicked on a thumbnail, then I could request any data from the server that I wanted via AJAX correct?

Awesome! I should have guessed that there was a way to do this. Thanks very much.

 

BTW, I checked out your site and I love the contents. It might just be me, however I would love to see a compressed version of the page with just the headers. I hated having to scroll down the huge page to see what other cool topics you had about PHP.

 

Thanks again!!

Jay,

 

Just one more thing. I see people using CPAINT2 as a framework for using AJAX. If you know anything about it, can you tell me how I would go about using it to request a file from the server? I tried using my own AJAX script below:

 


function loadXMLDoc()
{
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("overlay_info_contents").innerHTML=xmlhttp.responseText;
    alert("yes this is active!");
    }
  }
xmlhttp.open("GET","http://ceruleansin.byethost3.com/gallery/libraries/ajax_info.txt",true);
xmlhttp.send();
}

 

I think it didn't work because CPAINT is already in use and there might be a conflict in the xmlhttp.onreadystatechange.

 

 

Thanks!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.