Jump to content

Local running AJAX / Apache


dennisnmgn

Recommended Posts

somehow i can not run AJAX localmachine with Apache... anyone can help me with this problem ?

this source i use:

it did work on the webserver..

 

index.php

 

<?php

session_start();

function isin($word, $string) {

$length = strlen($word);

for($a=0;$a<$length;$a++){

$output = substr($word,$a,strlen($string));

if ($string == $output) { return true; }

}

}

#include "../config/db.php";

#include "../config/ip.php";

?>

<script type="text/javascript">

var http = false;

 

if(navigator.appName == "Microsoft Internet Explorer") {

  http = new ActiveXObject("Microsoft.XMLHTTP");

} else {

  http = new XMLHttpRequest();

}

 

function retrievewr(url) {

alert(url);

  http.abort();

  http.open("POST", "radio/winamp/waradios.php?&channel=" + url, true);

  http.onreadystatechange=function() {

    if(http.readyState == 4 && http.status == 200) {

      document.getElementById('RRadios').innerHTML = http.responseText;

    }

    if(http.readyState == 4 && http.status != 200) {

      setTimeout("retrievewr(url)", 1);

    }

  }

  http.send(null);

}

</script>

<style>

td.Cchatters {

width: 90px;

font-size: 8pt;

font: ARIAL;

}

</style>

 

<table border=1 width=20%>

<tr>

<td valign=top class="Cchatters" width=30%>

<img src="../../chat2/design/optionfield-RoomsChatters.gif" onmouseover="javascript:display('rooms_show');nodisplay('chatters_show');validaterooms();">

<div id=Crooms style="position:relative;z-index: 7;margin-top: -30px; padding-top: 5px; color: black; text-align: center; width: 100px;"><b>Winamp's<b></div>

</td>

<td valign=top class="Cchatters" width=30%>

<img src="../../chat2/design/optionfield-RoomsChatters.gif" onmouseover="javascript:nodisplay('rooms_show');display('chatters_show');">

<div id=Crooms style="position:relative;z-index: 7;margin-top: -30px; padding-top: 5px; color: black; text-align: center; width: 100px;"><b>Radio Stations<b></div>

</td>

<td valign=top class="Cchatters" width=30%>

<img src="../../chat2/design/optionfield-RoomsChatters.gif" onmouseover="javascript:nodisplay('rooms_show');display('chatters_show');">

<div id=Crooms style="position:relative;z-index: 7;margin-top: -30px; padding-top: 5px; color: black; text-align: center; width: 100px;"><b>Site DJ's<b></div>

</td>

</tr>

<tr>

<td colspan=3 width=100%>

<?php include "cathegorys.php"; ?>

<?php include "waradios.php"; ?>

</td>

</tr>

</table>

 

 

cathegorys.php

 

<style>

#RMenu {

display: block;

position:absolute;

width: 400px;

height: 200px;

overflow: scroll;

font-size: 8pt;

font: ARIAL;

scrollbar-face-color: #0D2623;

scrollbar-shadow-color: #0B5D51;

scrollbar-highlight-color: #004C49;

scrollbar-3dlight-color: #27847A;

scrollbar-darkshadow-color: #004C49;

scrollbar-track-color: #05372B;

scrollbar-arrow-color: #28887D;

scrollbar-base-color: #0D2623

border: 1px solid black;

}

</style>

<?php

## Scan Radio Menu.

$divname = "RMenu";

$menu = "href=\"/media/radio/";

$url = "http://www.winamp.com/media/radio/";

## Scan Radio Classes.

$filehandle = fopen($url, "r");

$total = "0";

echo "<div id=".$divname." style=\"position:relative;\">";

while (!feof($filehandle)) {

$line = fgets($filehandle, 4096);

$line = str_replace("class=\"selected\" ", "", $line);

$line = str_replace(" class=\"odd\"", "", $line);

$line = str_replace("&#187;", "", $line);

$line = str_replace(" ", "", $line);

$line = str_replace("title=\"Listen\">", "", $line);

$line = str_replace("<img align=\"absmiddle\" hspace=\"5\" src=\"http://media.winamp.com/main/images/buttons/listen.gif\" border=\"0\" alt=\"Listen\">", "", $line);

$line = str_replace("  ", " ", $line);

if (isin($line, $menu) == "true") {

$total++;

$cathegory = preg_replace('/\<li\>\<a href=\"(.*)\">(.*)/', '$2', $line );

$cathegory = str_replace(" ", "", $cathegory);

$cathegory = str_replace("</a></li>", "", $cathegory);

if ($cathegory == "Top50") echo '<a href="javascript:retrievewr(\'/\');">';

if ($cathegory != "Top50") echo '<a href="javascript:retrievewr(\'/'.$cathegory.'\');">';

echo $cathegory;

echo '</a><br>';

}

}

fclose($filehandle);

echo "</div>";

?>

 

 

waradios.php

 

<style>

#RRadios {

display: block;

position:absolute;

width: 400px;

height: 200px;

overflow: scroll;

font-size: 8pt;

font: ARIAL;

scrollbar-face-color: #0D2623;

scrollbar-shadow-color: #0B5D51;

scrollbar-highlight-color: #004C49;

scrollbar-3dlight-color: #27847A;

scrollbar-darkshadow-color: #004C49;

scrollbar-track-color: #05372B;

scrollbar-arrow-color: #28887D;

scrollbar-base-color: #0D2623

border: 1px solid black;

}

</style>

<?php

function isinn($word, $string) {

$length = strlen($word);

for($a=0;$a<$length;$a++){

$output = substr($word,$a,strlen($string));

if ($string == $output) { return true; }

}

}

## Scan Radio Menu.

$divname = "RRadios";

$menu = "href=\"/media/radio/";

$url = "http://www.winamp.com/media/radio";

$url .= $_REQUEST['channel'];

## Scan Radio Classes.

$radio = "tunein-station.pls?id=";

$filehandle = fopen($url, "r");

$total = "0";

echo "<div id=".$divname." style=\"position:relative;\">";

while (!feof($filehandle)) {

$line = fgets($filehandle, 4096);

$line = str_replace("class=\"selected\" ", "", $line);

$line = str_replace(" class=\"odd\"", "", $line);

$line = str_replace("&#187;", "", $line);

$line = str_replace(" ", "", $line);

$line = str_replace("title=\"Listen\">", "", $line);

$line = str_replace("<img align=\"absmiddle\" hspace=\"5\" src=\"http://media.winamp.com/main/images/buttons/listen.gif\" border=\"0\" alt=\"Listen\">", "", $line);

$line = str_replace("  ", " ", $line);

if (isinn($line, $radio) == "true") {

$line = preg_replace('/\<li\>\<a href=\"(.*)\"(.*)\<\/a\>/U', '$2', $line );

$line = preg_replace('/  \<strong\>\<a href=\"(.*)\" title=\"(.*)\">(.*)\<\/a\>\<\/strong\>/U', '<a href=$1>$3</a>', $line );

echo $line;

echo '<br>';

}

}

fclose($filehandle);

echo "</div>";

?>

 

Regards.

Link to comment
https://forums.phpfreaks.com/topic/80634-local-running-ajax-apache/
Share on other sites

As long as your web server can show a regular webpage, then it supports "AJAX". There is no server limitation, just the browser. AJAX uses basic HTTP, it is just a browser method where a new page is requested without reloading the current page. So you request a new page programmatically with JavaScript.

 

Try something simple like:

 

<script type="text/javascript">
var http = false;

try {
  http = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
  http = new XMLHttpRequest();
}

function retrievewr(url) {
  alert(url);
  http.abort();
  http.open('get', 'hello.php');
  http.onreadystatechange=function() {
    if(http.readyState == 4 && http.status == 200) {
     alert(http.responseText);
    }
  }
  http.send(null);
}
</script>

 

Then in your PHP file: hello.php have:

 

<?php
echo "hello AJAX!";
?>

 

If you use firefox, download the Firebug extension. It allows you to view XMLHttpRequests made.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.