开发者

Ajax loading of scripts (using jQuery) from CDN is't working

开发者 https://www.devze.com 2023-02-02 10:48 出处:网络
In my Javascript heavy Web app, I have some scripts that are loaded in the sourc开发者_如何学JAVAe HTML withtags, and others that I load as needed using jQuery\'s ajax method.

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消