PDA

View Full Version : URL problems?


student101
04-29-2008, 08:07 AM
When using frames, javascript, dhtml, ajax or anything else that is possible.
This script below will load the main page (in this case index.php) as the master page and the frame/page/div will load accordingly.
<script type="text/javascript">
<!--
if (self == top){
var url = self.location;
self.location = "index.php?" + url;
}
// -->
</script>The PROBLEM:
The URL that gets created is the actual problem.
If I add this in the page called links.php
I load the links.php and the browser's URL looks like this:
http://localhost:81/site/index.php?http://localhost:81/site/links.php
All I need is the URL to be like this:http://localhost:81/site/index.php
Is there a better or other way of doing this?
Cheers

pete
04-29-2008, 05:52 PM
Change it to:

<script type="text/javascript">
<!--
if(self == top) self.location = "index.php";
// -->
</script>

student101
04-29-2008, 06:21 PM
I have tried that method but it wont load the page needed to load.

If I load links.php then your method will only load index.php and not the links.php page

Cheers

pete
04-29-2008, 06:25 PM
I have tried that method but it wont load the page needed to load.

If I load links.php then your method will only load index.php and not the links.php page

Cheers

Of course, that is what you asked for.

When using frames, javascript, dhtml, ajax or anything else that is possible.
This script below will load the main page (in this case index.php) as the master page and the frame/page/div will load accordingly.

The above makes no sense, can you post a page because from the above I am unclear what you are wanting to achieve.

student101
04-29-2008, 06:42 PM
I have attached the files for you to see what I mean.

If you try to load one of the external.htm files it does not load the main index.htm

Cheers

pete
04-29-2008, 07:06 PM
In each external in ajaxfiles/ directory put the following JS


<script type="text/javascript">
if(location.href.indexOf("ajaxfiles")>-1){
location.href='../index.htm?uri=external.htm';
}
</script>



Change the uri to the name of the external page.

In index.htm add the following code:


window.onload = function(){
if(location.search.indexOf('uri=')>-1){
var loc = location.search.split('=');
ajaxpage('ajaxfiles/'+loc[1]+"","rightcolumn");
}
}

Then if someone navigates to external.htm they get redirected to ajaxcars/index.htm?uri=external.htm and it loads that page.

Is that what you wanted?

student101
04-29-2008, 07:07 PM
I will try it right now.

That works great, how to fix the uri or URL to display only the index.htm
http://localhost:81/ajaxfiles/index.htm?uri=external.htm
from that to this: (and load still the external.htm file that was asked for)
http://localhost:81/ajaxfiles/index.htm
If it's possible then cool/bonus/great - if not then it's no train smash.

How did you figure that out? That's damn cool to just know it when you see it.

Cheers

pete
04-29-2008, 07:10 PM
Example

http://www.codecreate.co.uk/ajaxcars/index.htm

student101
04-29-2008, 07:16 PM
What am I looking for?

Here is my PHP version of this Axaj/dHTML/javacsript stuff:
$allowed = array('index.php',
'links.php',
'contact.php',
'home.php'
);

if(in_array($_GET['pathid'], $allowed))
{
if(isset($_GET['pathid']))
include('./'.$_GET['pathid']);
//include($_GET['pathid']);
}else{
// error do nothing except tell them off in a nice way.
echo "<BR>";
echo "<BR>";
echo "Busted, got you this time!";
}
Cheers and Thanks

pete
04-29-2008, 07:35 PM
I will try it right now.

That works great, how to fix the uri or URL to display only the index.htm
http://localhost:81/ajaxfiles/index.htm?uri=external.htmfrom that to this: (and load still the external.htm file that was asked for)
http://localhost:81/ajaxfiles/index.htmIf it's possible then cool/bonus/great - if not then it's no train smash.

Cheers

You need the link in the url unless you use PHP or similar then you can do tricks with sessions.

The script you have is actually not ideal, I would never expose or even create static pages in ajaxfiles/ like that. It is much better to use JSON and fill place holders rather than ram in static pages, you may as well use an iframe in this example. This is a perfect example of XHR (ajax is the name a marketing guy gave it, use XHR instead :)) used incorrectly.

pete
04-29-2008, 07:36 PM
What am I looking for?

I uploaded it so you can see a working example and therefore follow the example I uploaded if you got stuck.

pete
04-29-2008, 07:43 PM
What am I looking for?

Here is my PHP version of this Axaj/dHTML/javacsript stuff:
$allowed = array('index.php',
'links.php',
'contact.php',
'home.php'
);

if(in_array($_GET['pathid'], $allowed))
{
if(isset($_GET['pathid']))
include('./'.$_GET['pathid']);
//include($_GET['pathid']);
}else{
// error do nothing except tell them off in a nice way.
echo "<BR>";
echo "<BR>";
echo "Busted, got you this time!";
}
Cheers and Thanks





There is no point in a PHP version like the above, although if you are learning PHP then it is good you are finding solutions yourself. You would be better using mod_rewrite though and a database to store your cars in. By using a database you can then create a search function etc, as your site grows you will be able to handle it. If you have 500 cars listed do you really want 500 static pages?

1 car detail page, proper use of mod rewrite and mysql can handle over a million cars and your site can be made SE friendly to bring in more traffic.

student101
04-29-2008, 07:44 PM
Cool, just wanted to load different URLs without refreshing the entire page.

Cheers

student101
04-29-2008, 07:57 PM
There is no point in a PHP version like the above, although if you are learning PHP then it is good you are finding solutions yourself. You would be better using mod_rewrite though and a database to store your cars in. By using a database you can then create a search function etc, as your site grows you will be able to handle it. If you have 500 cars listed do you really want 500 static pages?

1 car detail page, proper use of mod rewrite and mysql can handle over a million cars and your site can be made SE friendly to bring in more traffic.

Cool, will have to find some GOOD mod_rewrite tuts.

That demo isn't for me, it's from dynamic drive.
I am using it in a site that I am re-doing from TABLES to CSS (fun job, that's finally complete)
The objective was to allow the SWF/Flash file keep running without reloading the pages.
All that is left is to add the database stuff.

Cheers