In Chrome Inspector console, a never-ending JavaScript loop is triggered by a modification in the htaccess file to create pretty URLs, specifically when

Brand new to the world of .htaccess modifications and handling clean URLs.

I currently have a php/bootstrap/mysql/javascript page at: http://localhost/modules/posts/questions_all.php.

I am interested in redirecting pages such as http://localhost/modules/posts/questions_all.php/1234 back to the original page.

I've made changes to my .htaccess file as follows:

RewriteEngine On    # Activate the rewriting engine
RewriteRule    ^modules/posts/questions_all.php/?$    modules/posts/questions_all.php    [NC,L] 

The redirection seems to work but it triggers an endless loop of javascript that repeatedly adds portions of code, making the page messy.

In the Chrome console inspector, I encounter an error that doesn't occur when the page loads normally. However, with /1234 added to the end of the URL, the error message is:

DevTools failed to parse SourceMap: http://localhost/modules/posts/questions_all.php/bootstrap.min.js.map
[Violation] Forced reflow while executing JavaScript took 32ms

The request for the SourceMap does NOT happen on the original page, which functions flawlessly without console errors.

This issue also arises in firefox, so it doesn't seem to be related to disabling the SourceMap feature in the Chrome Inspector. Even with the Chrome inspector turned off, the problem persists.

I have employed similar .htaccess modifications for other pages (with bootstrap) to achieve clean URLs without encountering this error. It seems to be specific to this particular page...!

Thank you in advance for any assistance!

[EDIT]: Upon further investigation, the problem appears to be linked to an infinite scroll script, though it's still unclear why it causes an infinite loop. The purpose of the script is to dynamically load content until reaching the bottom of the screen, then halt. Everything works fine without the addition of /1234 to the URL, but once it's included, the script enters into an infinite loop and executes other parts of the code as well.

The load_data function initiates an AJAX call to fetch data.

Below is the relevant code snippet:

//autoload portion.  when scrolling reaches the bottom of the screen, triggers another load of data
    $(window).scroll(function(){
        if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive'){  
            action = 'active';
            start = start + limit;
            setTimeout(function(){
            load_data(limit, start, search, tag);//recursive loading function
            }, 500);
        }
    });

Answer №1

It appears that the issue mentioned in the previous EDIT was not the root cause of the problem. The culprit turned out to be the URL reference within the AJAX calling function. Surprisingly, using htaccess necessitated specifying the complete URL with an http: reference for it to work properly.

$.ajax({

url:"questions_all_autoscroll_fetchdata.php" - the original worked without htaccess modifications, but stopped working after htaccess changes

url:"/questions_all_autoscroll_fetchdata.php" - still did not function correctly post-htaccess adjustments

url:"http://localhost/modules/posts/questions_all_autoscroll_fetchdata.php" - worked seamlessly with htaccess modifications.

...});

If anyone can shed light on why this behavior occurs, your input would be greatly appreciated. Additionally, if there is a workaround to make it function with a relative URL, that information would also be invaluable.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Javascript navigation menu failing to accurately display all pages

As I continue to enhance my website at , I have encountered an issue with the menu functionality. The menu is dynamically generated through JavaScript, scanning a folder for pages and populating them into an array. While this system functions smoothly ove ...

Error: Code layer not located while utilizing "sam invoke local" in AWS

Currently, I am engaged in an AWS project where I am developing two lambda functions. Both of these functions rely on a common codebase stored in the node_modules directory, which is placed in a separate layer named AWS::Lambda::LayerVersion, not to be con ...

"Unusual HTML and jQuery quirk causing a perplexing issue: a function that keeps looping inexp

A unique code written in javascript using jQuery allows users to create a "box" on a website with each click of a button, triggering an alert message upon clicking the box. The process is as follows: 1) Clicking the "Add (#addBox)" button appends a new li ...

How odd! Using window.location or location.replace redirects to the page and then reverses back!

While in debug mode, I am able to track which page is being accessed. Interestingly, whenever I use window.location or window.location.replace(..), the browser redirects to the specified page but then quickly returns to the original one! This strange beh ...

Here's a unique version: "Strategies for effectively closing a modal when moving to a

I'm currently working with react-router-dom and material UI modal, and I am looking for a way to automatically hide the modal whenever the user navigates to another page. Here is my App component: const App = () => ( <BrowserRouter> &l ...

Examining the order in which tabs are navigated

Ensuring correct tab keyboard navigation order within a form is crucial for one of our tests. Query: How can the tab navigation order be verified using protractor? Our current method involves repeating the following steps for each input field in a form ( ...

Can you explain how to add a string array to an HTML div using AJAX?

My output consists of a string array that comes from PHP JSON. I am trying to display this output in an HTML div tabcontent, but I'm unsure of how to achieve this. Below is a snippet of my code - can anyone help me with this? [{"id":"1","p_name ...

Encountering issue while starting npm: expressjs server facing problem with MongoDB

Running npm start on Windows went smoothly, but I encountered an error when trying it on macOS. The error message is as follows: > node ./bin/www.js www error: SyntaxError: Unexpected token ? If you require any additional information, please do not he ...

What is the best way to display a popup using slimbox when the page loads, but only for the initial visit?

I have been exploring the idea of creating a function called popup("url") that checks for an existing cookie when the page body loads (onLoad - not ideal, I know). To implement this functionality, I used the code from this source and included it in my appl ...

Steps to generate a nested list with heading tag elements in the exact order as in the DOM structure

My HTML document is full of h1, h2, h3, h4 tags with nesting. Let's take a look at an example. <h2>About cars</h2> <p>Information about cats</p> <h2>About bikes</h2> <p>Information about bikes</p> ...

What is the best way to attach functions to specific jQuery objects and exclude others?

Imagine having an unordered list <ul>: <ul class="products"> ... </ul> You want to use jQuery to select it and then add custom functions to that specific object. For instance, you wish to include an addProduct(productData) function ...

React Login Redirect

I am struggling to implement a redirect in my React project login. Despite researching online and finding solutions using routers, I have been unsuccessful in adding it to my code correctly. Here is my code - how can I effectively implement the router? Ap ...

Creating a custom design for legends in Chart.js

I'm currently working on a project using chart.js and I'm trying to customize the label/legend styling for my chart. My goal is to replace the rectangular legend with a circular one. I've come across the suggestion of creating a custom legen ...

By clicking the button, you can add an item to select2

Utilizing the select2 tag style in my Drupal YAML form allows users to easily locate and add various items. These items come with both images and titles on the same page, accompanied by a button next to each image. My goal is to enable users to click the b ...

Encountering the issue of "TypeError: Cannot read property 'file' of undefined" when trying to upload a video with Multer

The objective is to select a video file from the desktop and upload it to the platform. The uploaded video file will then be automatically posted to a specified Youtube channel using GCD. An error message I encountered is:"react-dom.development.js:40 ...

Conceal or eliminate the Next.js runtimeConfig before making network requests and receiving responses

In my next.js project, I am utilizing .yml files due to Docker and incorporating these configurations in the next.js runtimeConfig. However, these configurations are visible in the browser's network tab as they are included in the document response. ...

What advantages and disadvantages come with using timeouts versus using countdowns in conjunction with an asynchronous content loading call in JavaScript/jQuery?

It seems to me that I may be overcomplicating things with the recursive approach. Wait for 2 seconds before loading the first set of modules: function loadFirstSet() { $('[data-content]:not(.loaded)').each( function() { $(this).load($(thi ...

Is there a way for me to link my script for use in a Detail.cshtml file?

I have added the following script to my _Layout.cshtml shared master view: <script src="@Url.Script("~/Scripts/PromptToSave.js")" type="text/javascript"></script> Is there a way to include this script in a Details or index page that does not ...

Dynamically loading JQuery causes highcharts to encounter errors

I have limited experience with JavaScript programming, and I've been encountering a persistent issue for quite some time now. Any assistance on this matter would be greatly appreciated. In the provided jsfiddle example, when jQuery is selected from t ...

Incorporating a computed variable in a v-select within a VueJs endless loop

I've been attempting to utilize a computed value in a v-select component from Vuetify, but every time I select an item, it triggers an endless loop. To demonstrate the issue, I have recreated my code in this CodePen. Please be cautious as it may caus ...