PDA

View Full Version : XMLHttpRequest returns 404 on Php files



urbanvintner
09-24-2010, 07:24 AM
If you want to recreate the error go here (http://www.tlcnz.com) and click on the contact us link in the horizontal menu under the masthead. In the interests of the site not being totally non-functional I have removed the query string entirely from all the other other links and replaced them with individual files for each one - except for the link to the contact form. I do need a generic solution for some of the functionality which the menu.swf file uses. Plus it used to be nice and elegant. This all used to work...I am mystified at how I managed to break it.

I replaced my original XMLHttpreq routine with an ajax one and now I can load html, and php... but not if the php has a query string. Any ideas why? Javascript (http://www.tlcnz.com) and Php code are in responses below.

bluewalrus
09-24-2010, 01:09 PM
Try alerting the variable url to see what it is being set as, or post a link/whole code.

jscheuer1
09-24-2010, 02:24 PM
What's the syntax of your jQuery ajax? What's the PHP code look like on the page that gets loaded with the query string? I'm assuming it has includes or requires on it, perhaps they are the 404 error. If you haven't already, make the include(s)/require(s) on bloader.php use the absolute path.

Later:

Oh, I see the code now, you should probably not set a timeout:


$.ajax({
url: url,
timeout:5000,
success: function(data){
msg.html('');
container.
html(data)
if(url=="event.html"){
gotoframe(99);
thisMovie("menu").HTMLtojava();
}
dhtmlHistory.add(url, container.html);
},
error: function( . . .

But I don't think that's it, once it gets the 404, it is completing. I put my money on the paths for any included files on bloader.php.

urbanvintner
09-24-2010, 03:44 PM
I tried your suggestion of absolute path. URL file-access is disabled though so that results in a PHP error. Also I am using a relative path on the php files without query strings. In the interests of the site not being totally non-functional I have removed the query string entirely now and replaced them with individual files for each link - except for the link to the contact form. You can click on that if you want to recreate this error. I do need a generic solution for some of the functionality which the menu.swf file uses. Plus it used to be nice and elegant. This all used to work...I am mystified at how I managed to break it.

My Javascript is attached. Here is the PHP I am using. This is bloader.php which Ajax comes back with a 404 on

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
<?PHP require_once('blog/wp-blog-header.php');?>
<?PHP
$name = $_GET['name'];
query_posts('pagename='.$name);while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(''); ?>
<?php endwhile; ?>
And here is about.php which works, and is exactly the same. It just doesn't require a query string.

<?PHP require_once('blog/wp-blog-header.php'); ?>
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
<?PHP $name = "about";
query_posts('pagename='.$name);while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(''); ?>
<?php endwhile; ?>

jscheuer1
09-24-2010, 04:38 PM
I tried your suggestion of absolute path. URL file-access is disabled though so that results in a PHP error.

That's unfortunate. From your PHP code it looks as though more of that sort of thing may be happening on the required files, these should be network paths. And/or that there may be functions on the required file that use paths, these should also be network paths.

The problem is, if you include a file on a page, its relative paths are relative to the page it's included on. However, if it's part of an AJAX request, there may be no relative path that would be correct.

If you cannot use the absolute path, try the network path -

Example absolute path:


http://www.mydomain.com/includes/required.php

Equivalent network path:


/includes/required.php

Notice the / at the beginning. That tells the server to begin at the root of the domain. So for all intents and purposes it's just like an absolute path.

I really don't think this is a problem on bloader, though it may be. Rather one on blog/wp-blog-header.php and any files it includes. Best though to make them all network paths. Try it with just one on one of the pages that works already just to see if the server accepts it.

I'm thinking things worked before because there were only single includes, then you expanded to include pages from included pages. If I'm guessing right, that's when things stopped working.

urbanvintner
09-24-2010, 10:43 PM
this is the result

Fatal error: require_once() [function.require]: Failed opening required '/blog/wp-blog-header.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/tlcnzcom/public_html/about.php on line 1

Thanks Again

urbanvintner
09-24-2010, 10:46 PM
Also if its the include, why is it erroring out only when I apply a query string

jscheuer1
09-25-2010, 01:04 AM
Also if its the include, why is it erroring out only when I apply a query string

I was thinking that too. Looks like it's fixed now. What was it, something on the server?

urbanvintner
09-25-2010, 01:32 AM
I figured out that the variable name in the query string was the problem. I changed that and it worked fine, all I can figure is that the wordpress header, which was the included file uses that query string itself, and that upgrading word press is what broke it in the first place

jscheuer1
09-25-2010, 04:26 AM
Oh! (hits self on forehead), so that was it. Makes sense in a weird sort of way. Hopefully I'll remember that if it ever comes up again.

urbanvintner
09-25-2010, 06:05 AM
Yep... thanks for all your help incidentally