In my Javascript heavy Web app, I have some scripts that are loaded in the sourc开发者_如何学JAVAe HTML with tags, and others that I load as needed using jQuery's ajax method.
I am in the process of relocating most of my app's static assets to a CDN (I'm using AWS Cloudfront). My dynamic loads no longer work. The jQuery Ajax call:
$.ajax({
url: url,
dataType: 'script',
async: true,
success: function (content) {
....
triggers the success function, but the content is empty.
I'm wondering if this is because such a request violates the Browser's security model for cross-site scripting. If that's the case, is there to load scripts dynamically from a CDN? Ahhh... I am NOT presently using a CNAME alias for the cloudfront host. Would doing so solve this problem?
You're right, it is the cross-site scripting security preventing this.
You're able to use the jQuery.getScript() method to load it from an external domain (or internal).
精彩评论