문제

In my Javascript heavy Web app, I have some scripts that are loaded in the source 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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top