0

I am currently loading a model with jQuery's .load. After it has been successfully loaded, I would like to execute some JavaScript which has dependencies on the loaded model.

buildFindOrderDialog: function () {
    workflowDialogContent.load('../../csweb/Orders/FindOrderDialog/', function () {
        $.getScript('~/Scripts/FindOrderDialogModel.js');
        workflowDialog.dialog('open');
    });
}

The load method executes the Order Controller's FindOrderDialog method which returns a ViewModel. After this has loaded, I want to run my FindOrderDialogModel javascript to affect the model client-side.

The above code does not properly load the javascript. I am wondering: does my controller have to provide a method for loading the javascript? The client has no concept of the relative path.

Of course, I could inline the script with the FindOrderDialog view, which would cause it to execute after load, but this seems like a bit of a hack.

UPDATE: My syntax was just a bit off. This works:

buildFindOrderDialog: function () {
    workflowDialogContent.load('../../csweb/Orders/FindOrderDialog/', function () {
        $.getScript('../Scripts/Orders/FindOrderDialogModel.js');
        workflowDialog.dialog('open');
    });
},

1 Answer 1

1

If I understand your question correctly, how about either

$.getScript('Scripts/FindOrderDialogModel.js');

Alternatively specify the full path:

$.getScript('/My/Full/Path/Scripts/FindOrderDialogModel.js');

Or finally, inject the relative path via ASP.NET:

$.getScript('<%= .NET CODE FOR RETRIEVING PATH USING THE ~ SIGN %>');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.