Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post

    ajaxfilefetcher not so good if file is php

    I have used the script ajaxfilefetcher http://www.javascriptkit.com/script/script2/ajaxpagefetcher.shtml several times and it has worked quite nicely with text files.

    Where I have a problem now, is when the file being called to fill the div is a php file. It is kind of dawning on me that this may not work. Anyhow continuing...

    The php file contains a MySQL query which works fine when run as an independent file. -- I am thinking as I am typing.. that the page has already been served up by the php engine, and it won't process a embedded php file within a page that has already been served up.

    So that brings me to a new question. Is there a simple ajax script that can just make a MySQL query and deliver the contents of that query to the page in question on the fly. It appears PHP wont work unless I reload the whole page.
    Last edited by mndasher; 06-13-2009 at 05:31 PM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You make the php page that you call return just the content that you want. There is no need to return an entire page if you do not need it.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New Coder
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post
    The php page is about as simple as it can get - It returns one echo statement.

    Code from calling page

    PHP Code:
    <a class="main" href="javascript:ajaxpagefetcher.load('<?php echo $divCode?>', 'quickAjaxGrab.php?page=<$php echo $ajaxID ?>', false, '', [''])">Read More...</a>
    Code from page doing the insert;

    PHP Code:
    include ('connect2db.php'); 

    $ajaxID$_GET['page'];

    $query "SELECT MoreText FROM content WHERE ID = ".$ajaxID;

    $result mysql_query ($query$link);

    if (!
    $result) {  echo 'Could not run query: ' mysql_error();
    exit();
    }
    $a_row mysql_fetch_row ($result);

    echo 
    stripslashes($a_row[0]); 
    When I run this as standalone it runs fine.

    When ajaxfilefetcher gets it. Message is: "Loading Page, please wait..." That message never goes away.
    Last edited by mndasher; 06-13-2009 at 02:37 PM.

  • Users who have thanked mndasher for this post:

    murray (06-30-2009)

  • #4
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Guessing that it is not returning back correct data. With firebug, you can enable it to see the XMLHttpRequest. Do that and look at what is happening. I am guessing it is returning something other than a 200 back.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #5
    New Coder
    Join Date
    Jun 2009
    Posts
    15
    Thanks
    0
    Thanked 1 Time in 1 Post
    Ok - I have it working

    The problem was a little subtle. I was running on localhost, but index.php has a <base href="http://www.mywebsite.com/"> tag in it. As soon as I took that out it worked.

    The problem was a about 500 lines away from where I was looking.

    Firebug sort of pointed the way. Thanks for suggesting using that.

    This is pretty slick. Whew! Spent a few hours on this. I should of uploaded it - it would have worked on the target site.


  •  

    Posting Permissions

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