-
Notifications
You must be signed in to change notification settings - Fork 20.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jQuery .load function errors if loading html with auto-removing script tag #5377
Comments
🛠️ Addressing .load Function Error: Auto-Removing Script Tag Thank you for bringing attention to this issue! The problem with the .load function encountering errors when loading HTML with auto-removing script tags is crucial. This occurs due to the script tags being automatically stripped during the loading process, causing unexpected behavior. Issue SummaryThe current behavior leads to errors and may not handle the situation gracefully. Here's a suggested workaround to mitigate the problem: Workaround$("#targetElement").load("your.html", function(response, status, xhr) {
if (status == "error") {
// Handle error here, maybe log or alert
console.error("Error loading HTML:", xhr.statusText);
} else {
// Success logic
console.log("HTML loaded successfully!");
// Your additional logic here, if needed
}
}); ExplanationThe provided snippet includes an error-handling mechanism to manage cases where loading encounters issues. The status parameter in the callback function can be utilized to check for errors. If an error occurs, it logs the details using console.error. On successful loading, the success logic is executed. Proposed ResolutionIt would be beneficial for the .load function to handle scenarios with auto-removing script tags more gracefully. This could involve providing an option to suppress automatic removal or offering a more informative error handling approach. |
Don't try to remove a script element that has already removed itself. Fixes jquerygh-5377 Closes jquerygh-5378 (cherry-picked from commit 937923d)
Thank you :) |
Description
jQuery
.load
function errors if loading html with auto-removing script tag. Callback function is not executed.While this is kind of a non-issue as jQuery removes scripts with the
.load
function anyways and can be fixed just by removing thedocument.currentScript.remove();
from the loaded file, it sort of breaks stuff when I need that file to be loaded elsewhere via different methods and do require the script removal.Link to test case
Not sure how to demonstrate the
.load
function with the links provided as I need more than 1 file to show the error. So, here's the two html files needed to reproduce the issue.File: test.html
File: test2.html
Error message:
The text was updated successfully, but these errors were encountered: