The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 6 of 6

Thread: Fetching Sajax php page using Ajax? Please Help

  1. #1

    Fetching Sajax php page using Ajax? Please Help

    Hello all,

    I'm a novice when it comes to using Sajax, Ajax, and PHP. I'm in the process of completing a web site that consists of Sajax, Ajax , and PHP, however I've ran into a slight problem. What I am trying to achieve is have Ajax or Sajax fetch a Sajax graffiti wall from an external php page I developed (wall.php), once Ajax or Sajax fetches wall.php I would like to have the fetch page (wall.php) placed in a CSS Div "#galleryLYR". Please visit :

    http://artectodesignstudios.com/artecto/index.php , you should see a graffiti sign, if you click the sign you'll see that Ajax is fetching wall.php and placing it in the CSS Div #galleryLYR but the graffiti wall posts/comments are not being fetched.

    http://artectodesignstudios.com/artecto/wall.php <-- this is the page I'm trying to fetch. If you visit this page you'll see that the graffiti wall is working correctly.

    Please help!

  2. #2
    No one can help me??? Is this impossible to do?

  3. #3
    Let me rephrase what I am trying to do.

    What I am trying to do is fetch a Sajax graffiti wall from an internal php page called "wall.php" onclick using Ajax, and place the fetched graffiti wall in a Div called "#galleryLYR". The problem is when I fetch the graffiti wall the messages and dates don't display. I've tried placing the Sajax script on my main page index.php but I received the same result. Any ideas what I can be doing wrong?

    Please visit :

    http://artectodesignstudios.com/artecto/index.php , you should see a graffiti sign, if you click the sign you'll see that Ajax is fetching wall.php and placing it in the #galleryLYR DIV but the graffiti wall posts/comments are not displayed!

    http://artectodesignstudios.com/artecto/wall.php <-- this is the page I'm trying to fetch.

    I've been working on this for two days and can't seem to figure out what I am doing wrong ...any help is appreciated

  4. #4
    biznuge's Avatar
    1,136
    posts
    Use the Fork Luke...
    without seeing your php and javascript snippets, this is a fairly unpossible task mate. post some code and you might get more feedback from someone...

    before you judge someone, you should walk a mile in their shoes. That way, when you judge them, you're a mile away, and you have their shoes...
    "A lack of planning on your part does not constitute an emergency on mine" - Danonthemoon
    She asked for a double entendre, so I gave her one...
    "screw ie. it can lick my balls" - A.J. Cates

  5. #5
    Sorry. I have posted the code below. Please help

    <-------- this is the graffiti wall sajax script ---------->

    <?php
    //
    // The world's least efficient wall implementation
    //
    require("Sajax.php");

    function colorify_ip($ip)
    {
    $parts = explode(".", $ip);
    $color = sprintf("%02s", dechex($parts[1])) .
    sprintf("%02s", dechex($parts[2])) .
    sprintf("%02s", dechex($parts[3]));
    return $color;
    }

    function add_line($msg) {
    $f = fopen("/tmp/wall.html", "a");
    $dt = date("Y-m-d h:i:s");
    $msg = strip_tags(stripslashes($msg));
    $remote = $_SERVER["REMOTE_ADDR"];
    // generate unique-ish color for IP
    $color = colorify_ip($remote);
    fwrite($f, "<span style=\"color:#$color\">$dt</span> $msg<br>\n");
    fclose($f);
    }

    function refresh() {
    $lines = file("/tmp/wall.html");
    // return the last 25 lines
    return join("\n", array_slice($lines, -25));
    }

    $sajax_request_type = "GET";
    sajax_init();
    sajax_export("add_line", "refresh");
    sajax_handle_client_request();
    ?>
    <html>
    <head>

    <script>
    <?php
    sajax_show_javascript();
    ?>
    var check_n = 0;
    var old_data = "--";

    function refresh_cb(new_data) {
    if (new_data != old_data) {
    document.getElementById("wall").innerHTML = new_data;
    setTimeout("refresh()", 1000);
    old_data = new_data;
    } else {
    setTimeout("refresh()", 2500);
    }
    document.getElementById("status").innerHTML = "Checked #" + check_n++;
    }

    function refresh() {
    document.getElementById("status").innerHTML = "Checking..";
    x_refresh(refresh_cb);
    }

    function add_cb() {
    // we don't care..
    }

    function add() {
    var line;
    var handle;
    handle = document.getElementById("handle").value;
    line = document.getElementById("line").value;
    if (line == "")
    return;
    sajax_request_type = "POST";
    x_add_line("[" + handle + "] " + line, add_cb);
    document.getElementById("line").value = "";
    }
    </script>


    <body onLoad="refresh();">

    <div id="entry_form"><!--begin entry_form -->
    <form name="f" action="#" onSubmit="add();return false;">
    Name: <input type="text" name="handle" id="handle" value="(name)" onFocus="this.select()" style="width:200px;"/><br />

    Message: <input type="text" name="line" id="line" value="(write your message here)" onFocus="this.select()" style="width: 300px;" /><br />

    <input type="button" name="button" value="Submit" onClick="add(); return false;" />

    </form>

    <div id="wall"><!--wall begins--> </div><!--/end wall-->

    <div id="status"><!-- begin status--> <em>Loading..</em></div><!--/end status-->

    </div><!--/end entry_form-->

    <--------- this is the Ajax script to fetch wall.php and place it in div on index.php-------->

    var XMLHttpRequestObject = false;

    if (window.XMLHttpRequest) {
    XMLHttpRequestObject = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
    XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
    }

    function getData(dataSource, divID)
    {
    if(XMLHttpRequestObject) {
    var obj = document.getElementById(divID);
    XMLHttpRequestObject.open("GET", dataSource);

    XMLHttpRequestObject.onreadystatechange = function()
    {
    if (XMLHttpRequestObject.readyState == 4 &&
    XMLHttpRequestObject.status == 200) {
    obj.innerHTML = XMLHttpRequestObject.responseText;
    }
    }

    XMLHttpRequestObject.send(null);
    }
    }

    <body>

    <div id="sign"><!--sign begins-->
    <img src="/artecto/images/grafsign.png" alt="graffiti wall thumb" onClick="getData ('wall.php','galleryLYR') ">
    </div><!--/end sign-->

    </body>

  6. #6
    biznuge's Avatar
    1,136
    posts
    Use the Fork Luke...
    your response is supposed to be written into the 'galleryLYR' div, but i don't see this referenced in your code, except for it's use in the onclick event for use with the innerHTML...

    The code you've posted, isn't a single script is it? You'd do better to post the entire scripts, and use the vBulletin advanced formatting options to format them as code next time you post...

    before you judge someone, you should walk a mile in their shoes. That way, when you judge them, you're a mile away, and you have their shoes...
    "A lack of planning on your part does not constitute an emergency on mine" - Danonthemoon
    She asked for a double entendre, so I gave her one...
    "screw ie. it can lick my balls" - A.J. Cates

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012