Reputation: 846
$.ajax({
url: "test.html",
context: document.body,
success: function(){
$(this).addClass("done");
}
});
How do I run javascript within test.html and make it work ?
Thanks Abhinab
Upvotes: 0
Views: 186
Reputation: 5646
function call_recursive(){
var pages ["test1.html", "test2.html", "test3.html" ];
while(pages.length() > 0){
page = pages.pop();
$.ajax({
url: page,
context: document.body,
success: function(){
$("div#logger").append("<p>" + page " loded </p>");
},
error: function(){
$("div#logger").append("<p class'error'>" + page " is not loded </p>");
},
});
}
}
just execute call_recursive
Upvotes: 0
Reputation: 1824
It doesn't really work like that. Javascript in a page is interpreted by the browser when the page is loaded. In this case you aren't loading a page in the browser, you're just getting the page in your ajax response. That response HTML may have <script> elements in them, but nothing is going to do anything with it.
I hesitate to even say this, but you could parse the response in your success function to find all of the script elements, then add whatever you're looking for to your own page's DOM. That should cause the script to be fetched and evaluated. I hesitate to mention it because it smells really bad. If any of my developers did this we'd be having a tough conversation. ;-)
It might help to elaborate on what you're trying to accomplish, as there might be a more elegant way to achieve your goals.
Upvotes: 1