Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7446883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:27:20+00:00 2026-05-29T12:27:20+00:00

I am attempting to do some dynamic loading that includes javascript, css, and html

  • 0

I am attempting to do some dynamic loading that includes javascript, css, and html files.

I would like to do it like this:

$.when($.ajax(htmlPath), $.get(cssPath), $.ajax({
    url: javascriptPath,
    dataType: "text"
}))
.done(function(response){
// i want to pass the data for each of these to the respective functions        
    appendHtml(what goes here??);       
    appendCss(what goes here??);
    executeJs(what goes here??);
})
.fail(function(){
    console.log("failed");
});

So I’m confused on how I separate out the response callbacks. Currently, the response object you see in my .done function is ONLY the HTML file which I called. This function is making the correct ajax calls, and the correct files are all being responded by the server, but how do I access them once ALL the calls are complete? Need this so I won’t be applying css/js to HTML which is not there yet, etc. Also, what I do is have the javascript file returned as a string and then i eval() it within the executeJs function. My understanding is that this is an okay use of eval because its the file being returned by our own server so I don’t see how it could be tampered with. Is this assumption correct?

Furthermore, in my appendCss function, I’m just adding it to a “style” element in the head. Is there a big issue with this? I am using all this to make a “widget/app based” functionality where I have a js,css,and html for each “app”, and I just want to query the server for them when they are needed and the app is loading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:27:21+00:00Added an answer on May 29, 2026 at 12:27 pm

    If your downloaded data is being retrieved from the same server as your original web page, then yes, generally, you would have the same level of trust in that code as you do in the code that’s already running in the browser.

    The problem with eval() in a context like this isn’t necessarily that you don’t trust the code coming back from your own server; it’s that someone might be able to alter the running javascript so that the javascriptPath variable points somewhere you didn’t expect it to.


    As far as your actual question goes, your done callback will actually be passed three parameters, because your when call included three promises.

    Because of the way that you defined your callback (as function(response)), you are only seeing the first one — the return value from the HTML call. The other two parameters are being ignored.

    Each of the three parameters that you are being passed will be an array of three elements: [wasSuccessful, statusText, jqxhr]. To do something useful with them, you could structure your callback something like this:

    $.when($.ajax(htmlPath), $.get(cssPath), $.ajax({
        url: javascriptPath,
        dataType: "text"
    }))
    .done(function(htmlResponse, cssResponse, jsResponse){
        if (htmlResponse[0]) {
            appendHtml(htmlResponse[2].responseText);
        }
        if (cssResponse[0]) {
            appendCss(cssResponse[2].responseText);
        }
        if (jsResponse[0]) {
            executeJs(jsResponse[2].responseText);
        }
    })
    

    (Assuming that you have the appropriate appendHtml, appendCss, and executeJs functions written already)


    There are some good examples on this page: http://api.jquery.com/jQuery.when/

    And this page has the documentation on the jqxhr object (the third element in each of the arrays that are passed to your done function): http://api.jquery.com/jQuery.ajax/#jqXHR

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im attempting to utilize some custom script and css files within an asp page.
I'm attempting to pull some data from a SQLite database so that I can
I'm attempting to build some C++ code that requires the Windows 7.0 SDK header
I am attempting to add some entities that I have created. When I try
I am attempting to get some information from a website, the info that I
I am attempting to write some Java code that takes an image from a
I'm attempting to transfer some files through WCF, but as soon as the method
I am attempting to redirect & rewrite some dynamic PHP URL's to pretty and
I am attempting to write some simple code in F#, and i get this
I'm attempting to parse some Wiki-style markup using the Javascript Creole Wiki Markup Parser

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.