Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: With mod_rewrite AJAX can't load data |
|
Author |
|
pauliusvitkus
Joined: 10 Dec 2014 Posts: 1 Location: Lithuania
|
Posted: Thu 11 Dec '14 7:20 Post subject: With mod_rewrite AJAX can't load data |
|
|
Rececntly I changed my platform URL from .com/company.php?id=50 to .com/company/company-name. Everything works good, except content, which should be loaded through AJAX.
My line in .htaccess:
Code: | RewriteRule ^company/([0-9a-zA-Z_-]+) company.php?id=$1 [NC,L] |
The piece of AJAX, which is not loaded:
Code: | $rec_total_pages = ceil($amount_of_recommendations_company_has/$rec_per_page); // 2
?>
<script>
$(document).ready(function() {
var track_click = 0; //track user click on "load more" button, righ now it is 0 click
var total_pages = <?php echo $rec_total_pages; ?>;
var taker = <?php echo $recommendation_taker; ?>;
$('#results').load("show_more_recs.php", {'page':track_click, 'taker':taker}, function() {track_click++;}); //initial data to load
$(".load_more").click(function (e) { //user clicks on button
$(this).hide(); //hide load more button on click
$('.animation_image').show(); //show loading image
if(track_click <= total_pages) //user click number is still less than total pages
{
$.post('show_more_recs.php',{'page':track_click, 'taker':taker}, function(data) {
$(".load_more").show(); //bring back load more button
$("#results").append(data); //append data received from server
$('.animation_image').hide(); //hide loading image once data is received
track_click++; //user click increment on load button
}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
alert(thrownError); //alert with HTTP error
$(".load_more").show(); //bring back load more button
$('.animation_image').hide(); //hide loading image once data is received
});
if(track_click >= total_pages-1) //compare user click with page number
{
$(".load_more").remove();
$(".animation_image").remove();
}
}
});
});
</script>
<?php
echo "<div id=\"results\"></div>
<a class=\"load_more more dark\" style=\"margin-left: 15px; margin-top: 5px; margin-bottom: 10px; cursor: pointer;\" id=\"load_more_button\"><span>Show more</span></a>
<div class=\"animation_image\" style=\"display:none;\"><img src=\"ajax-loader.gif\"> Loading...</div>
";
|
With new URL script can't even pass variables track_click, total_pages and taker. But there are no errors too.
What's the problem? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Thu 18 Dec '14 12:39 Post subject: |
|
|
What do you use? $_GET? $_POST? Anything else? |
|
Back to top |
|
|
|
|
|
|