PDA

View Full Version : ajaxfilefetcher not so good if file is php


mndasher
06-13-2009, 07:18 AM
I have used the script ajaxfilefetcher http://www.javascriptkit.com/script/script2/ajaxpagefetcher.shtml (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.

A1ien51
06-13-2009, 12:56 PM
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

mndasher
06-13-2009, 01:40 PM
The php page is about as simple as it can get - It returns one echo statement.

Code from calling page

<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;


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.

A1ien51
06-13-2009, 02:22 PM
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

mndasher
06-13-2009, 03:16 PM
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. :)