Reputation: 1953
I am creating an entirely ajax site and one of the issues is that you can't provide links to direct pages as a result. I made it so that it appends the name of the page into the url every time you click an ajax link, but now I need a php script in my main file that gets run EVERY time you click to load a page. This will check to see if any of the get variables are set and redirect you to the proper page. For example if I give you this link http://techxpertschico/techxperts/repair
then it should be able to load the appropriate content into the page rather than taking you to the homepage. I suspect that this will look similar to the code below. I just don't know how to make the ajax request happen on the isset request. I need help figuring out what to add to my php script.
<?php
if(isset($_GET['notsurewhatgoeshere'])) {
//load the appropriate page using jquery
}
?>
Here is the code for the ajax request
$('.ajaxAnchor').on('click', function (event){
event.preventDefault();
$('a .top').css({'background' : 'transparent'});
$('a .top').children().css({'background' : 'transparent'});
$(this).children().css({'background' : '#EEEEEE'});
var url = $(this).attr('href');
var shortened = url.substring(0,url.length - 5);
History.pushState({state:1}, shortened, shortened);
$.get(url, function(data) {
$('section.center').html(data);
});
});
If you need to see additional code please let me know and I will add it. Thanks!
Upvotes: 0
Views: 314
Reputation: 1
Don't quite understand your question, but anyhow, a javascript function can be triggered by certain event, by page onload, i.e or button onclick(); i.e. Click me. In myFunction(){ you can write Ajax function to perform post/get. Inside javascript function, you can reload the page by using document.location.href = 'your new http://';
Upvotes: -1
Reputation: 2604
If you place this .htaccess file in the root of your website, and your server is configured properly, it will make any and all url links land on index.php. From there you can inspect the requested URL and decide where to go.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
Inside Index.php, you can inspect the $_SERVER['REQUEST_URI'] element to break up the requested URL.
This is somewhat minimal and doesn't 100% answer your question, but the scope of what you want to do is a little bigger than a single answer.
Upvotes: 2