简体   繁体   中英

How load js.aspx file using REQUIRE.JS

I am working on Microsoft dynamic CRM, it has a file named ClientGlobalContext.js.aspx to provide Xrm Object and there are also lots of custom scripts. Some of these files are using Xrm object from ClientGlobalContext.js.aspx.

Now I want to manage all my Javascript files using require.js, but how can I load ClientGlobalContext.js.aspx using require.js ?

Here is what I'm trying

requirejs.config({
    //By default load any module IDs from js
    baseUrl: '',
     //here we set our js folder
    //config is relative to the baseUrl, and
    //never includes a ".js" extension since
    //the paths config could be for a directory..
     paths: {
                'jquery':'//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min',//set jQuery path you can also include your folder js
                'jqueryui':'//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min',// set jQuery ui path you can also include your folder js
                'SDK.JQuery':"sample_/Scripts/SDK.JQuery",
                'json2':"sample_/Scripts/json2",
                'new_connexx':"new_connexx",
                // 'new_common':"new_common",
                'new_moment':"new_moment.min",
                'new_controls':"new_controls",
                'ClientGlobalContext': 'ClientGlobalContext.js.aspx'
          },
    shim: {

    'new_controls': {
        deps: ['new_moment','new_connexx'],// here we are defining that it depends on jQuery

    },
    'new_connexx':{
        deps:['jqueryui']
    },
    'jqueryui':{
        deps:['jquery','json2','SDK.JQuery']
    },
    'SDK.JQuery':{
        deps:['ClientGlobalContext']
    },
    'new_moment':{
        deps:['jqueryui']
    },
    'new_common':{
        deps:['jqueryui']
    },
    'new_letter_wizard':{
        deps:['jqueryui']
    }



 },
});

Please suggest if there is some thing I'm missing

I found an easy fix. As you know from the comments, you don't include the .js extension as require tries to handle that for you. That turns out to not be a great solution for CRM 2011 since you're trying to use a file with a .aspx extension. ClientGlobalContext.js.aspx is useful but it's also dynamically generated so there isn't a static version available. The solution however is to add a query string. When require sees this, it won't try to tack on the .js extension for you, so just change this line:

'ClientGlobalContext': 'ClientGlobalContext.js.aspx'

to this:

'ClientGlobalContext': 'ClientGlobalContext.js.aspx?foo=bar'

You don't really care what the query string value is, it's just to prevent requirejs from being too smart for its own good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM