JQuery .get doesnt execute Javascript
By : user3810004
Date : March 29 2020, 07:55 AM
Any of those help Inline JavaScript won't execute unless you run eval() on it. You can read more about that here: Executing inside retrieved by AJAX Can scripts be inserted with innerHTML? code :
$.get(url, function(response) {
var newContent = $(response).find("#right"); //Find the content section of the response
var contentWrapper = $("#wrap"); //Find the content-wrapper where we are supposed to change the content.
var oldContent = contentWrapper.find("#right"); //Find the old content which we should replace.
oldContent.replaceWith(newContent);
//Find all inline script tags in the new content and loop through them
newContent.find("script").each(function() {
var scriptContent = $(this).html(); //Grab the content of this tag
eval(scriptContent); //Execute the content
});
});
<div id="right" data-page-name="index">
<!-- Content -->
</div>
<div id="right" data-page-name="about-us">
<!-- Content -->
</div>
$.get(url, function(response) {
var newContent = $(response).find("#right"); //Find the content section of the response
var contentWrapper = $("#wrap"); //Find the content-wrapper where we are supposed to change the content.
var oldContent = contentWrapper.find("#right"); //Find the old content which we should replace.
oldContent.replaceWith(newContent);
var pageName = newContent.attr("data-page-name");
pageSpecificActions(pageName);
});
function pageSpecificActions(pageName) {
if (pageName == "index") {
//Run the code for index page
} else if (pageName == "about-us") {
//Run the code for about us page.
}
};
|
jQuery, execute function on document load
By : Eric Ingemunson
Date : March 29 2020, 07:55 AM
I hope this helps . I think you have a typo on line 4, you have "$jquery.reject" instead of "$.reject" or "jquery.reject" EDIT: if someone ever gets here again, there were a couple things wrong with the origin post, first a typo, then a missing reference to jquery and then another missing reference to the CSS for the plugin.
|
Jquery .load() - How to execute Javascript in original document from loaded content
By : leafxiaoyan
Date : March 29 2020, 07:55 AM
seems to work fine DYou should use live() or delegate() because you are adding an element to the document (this is for jQuery < 1.7) code :
jQuery(document).ready(function() {
$('a.loader').click(function() {
$('#loadbox').load('loadme.html');
});
$('a.alerter').live("click", function() {
alert("I've been clicked!");
});
});
jQuery(document).ready(function() {
$('a.loader').click(function() {
$('#loadbox').load('loadme.html');
});
$('body').on("click", "a.alerter", function() {
alert("I've been clicked!");
});
});
|
jquery .load doesnt execute $ajax function
By : Fede Solano
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I wrote some code where one html file (file1.html) loads another html file (file2.html). file2.html (a form page) includes some small php code (calling session_start()), some form fields and some jquery javascript functions including a $.ajax() function which in turn calls a php file when inputs have been entered. When file1.html loads file2.html all jquery javascript functions of file2.html are executed well except the $.ajax() function. The $.ajax function does work correctly when I load file2.html (with $.ajax()) in the browser. Then I tried to solve the problem by moving the $.ajax function from file2.html to file1.html as indicated in the code below, but without success. , based on your submitted code, you have a syntax error. code :
$("#formResponse").html("There was an error submitting
the form. Please try again.");
$("#formResponse").html("There was an error submitting" +
" the form. Please try again.");
<script>
$(document).ready(function(){
$("#section1").load("file2.html", function(){
$("#myForm").submit(function(){
$.ajax({
type: "POST",
url: "step2_submit2ajx.php",
data: $("#myForm").serialize(),
dataType: "json",
success: function(msg){
$("#formResponse").removeClass('error');
$("#formResponse").addClass(msg.statusgeneral);
$("#formResponse").html(msg.statusgeneral);
},
error: function(){
$("#formResponse").removeClass('success');
$("#formResponse").addClass('error');
$("#formResponse").html("There was an error submitting the form. Please try again.");
}
});
//make sure the form doesn't post
return false;
}); //.ajax
}); //end anonymous success
});
</script>
|
Why does this Javascript document.write not execute?
By : papachal
Date : March 29 2020, 07:55 AM
seems to work fine you are inserting code in a script tag that you are also using to load an external script (jQuery). you should either do the one or the other.
|