Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS CRM 2013 adds version number to WebResources of script type

I have found strange issue in MS CRM 2013, and since it seems to be by design, I need help to find a way around it.

The issue is it's impossible to call getScript jQuery method from WebResource.

The CRM adds version string to the url, and this causes request fail with error 500.

For example, when I'm trying to call: /Organization/WebResources/Synchronization.js

The CRM turns this request into following: /Organization/WebResources/Synchronization.js?_=1402918931398 and it fails with server error 500.

Here is the sample code I'm using:

var settings = {
    url: "/Organization/WebResources/Synchronization.js",
    dataType: "script",
    success: function (data) {
       console.log("success");
    },
    error: function(jqXHR, textStatus, errorThrown) {
       console.log("error");
    }
};

$.ajax(settings);

Could you please point me, how I can find out when URL is changed?

like image 766
shytikov Avatar asked Jun 16 '14 12:06

shytikov


1 Answers

It turns, that this is jQuery caching feature.

If caching will be turned on in settings object, the issue will disappear. Like this:

var settings = {
    url: "/Organization/WebResources/Synchronization.js",
    cache: true,
    dataType: "script",
    success: function (data) {
       console.log("success");
    },
    error: function(jqXHR, textStatus, errorThrown) {
       console.log("error");
    }
};
like image 142
shytikov Avatar answered Oct 26 '22 23:10

shytikov