Page 1 of 1

[SOLVED] Any\All jQuery causes Non-Translatable Function Exception: The function 'xxx' could not be translated.

Posted: Mon Sep 18, 2017 8:31 am
by TaterJuice
jQuery works in Simulator, does not work in .js output. Unable to use any jQuery in CSHTML5.Interop.ExecuteJavascript.

Code: Select all

await Interop.LoadJavascriptFile(urlToHostedjQueryDOTjs);
Interop.ExecuteJavascript("$('#myElementID').show();");

Works in Simulator, NonTranslatable function Exception in JS output.

Tried setting noConflict:

Code: Select all

Interop.ExecuteJavascript(@"
    var jQuery = $.noConflict();
    jQuery('#myElementID').show();");

Works in Simulator, NonTranslatable function Exception in JS output.

Tried just using jQuery noConflict without declaring it:

Code: Select all

jQuery('#myElementID').show();

Error jQuery is not defined.

Here is the exception from the output when I try to execute a jQuery function:
JSIL.Browser.js?20179180925:201 Error: The function 'System.Void HTMLButtonTest.KendoUIButton::OnJSLoaded()' could not be translated.
at HTMLButtonTest_KendoUIButton.UntranslatableFunctionInvoked (JSIL.Core.js?20179180925:1228)
at CSHTML5_INTERNAL_InteropImplementation_$l$gc__DisplayClass7.Delegate_Invoke [as onCompleted] (JSIL.Core.js?20179180925:9344)
at Object.INTERNAL_InteropImplementation_LoadJavaScriptFiles (CSharpXamlForHtml5.js?20179180925:7548)
at CSHTML5_INTERNAL_InteropImplementation_$l$gc__DisplayClass7.$l$gc__DisplayClass7_$lLoadJavaScriptFiles$gb__5 (CSharpXamlForHtml5.js?20179180925:7614)
at HTMLScriptElement.Delegate_Invoke (JSIL.Core.js?20179180925:9344)
JSIL.Browser.WarningService.write @ JSIL.Browser.js?20179180925:201


JSIL.Browser.js?20179180925:199 Error: The function 'System.Void HTMLButtonTest.KendoUIButton::OnJSLoaded()' could not be translated.
at HTMLButtonTest_KendoUIButton.UntranslatableFunctionInvoked (JSIL.Core.js?20179180925:1228)
at CSHTML5_INTERNAL_InteropImplementation_$l$gc__DisplayClass7.Delegate_Invoke [as onCompleted] (JSIL.Core.js?20179180925:9344)
at Object.INTERNAL_InteropImplementation_LoadJavaScriptFiles (CSharpXamlForHtml5.js?20179180925:7548)
at CSHTML5_INTERNAL_InteropImplementation_$l$gc__DisplayClass7.$l$gc__DisplayClass7_$lLoadJavaScriptFiles$gb__5 (CSharpXamlForHtml5.js?20179180925:7614)
at HTMLScriptElement.Delegate_Invoke (JSIL.Core.js?20179180925:9344)
JSIL.Browser.WarningService.write @ JSIL.Browser.js?20179180925:199


JSIL.Host.js?20179180925:240 Uncaught Error: The function 'System.Void HTMLButtonTest.KendoUIButton::OnJSLoaded()' could not be translated.
at HTMLButtonTest_KendoUIButton.UntranslatableFunctionInvoked (JSIL.Core.js?20179180925:1228)
at CSHTML5_INTERNAL_InteropImplementation_$l$gc__DisplayClass7.Delegate_Invoke [as onCompleted] (JSIL.Core.js?20179180925:9344)
at Object.INTERNAL_InteropImplementation_LoadJavaScriptFiles (CSharpXamlForHtml5.js?20179180925:7548)
at CSHTML5_INTERNAL_InteropImplementation_$l$gc__DisplayClass7.$l$gc__DisplayClass7_$lLoadJavaScriptFiles$gb__5 (CSharpXamlForHtml5.js?20179180925:7614)
at HTMLScriptElement.Delegate_Invoke (JSIL.Core.js?20179180925:9344)

Re: Any\All jQuery causes Non-Translatable Function Exception: The function 'xxx' could not be translated.

Posted: Wed Sep 20, 2017 2:59 am
by JS-Support @Userware
Hi,

"$" is a reserved keyword for the "ExecuteJavaScript" method. It is used to pass arguments to the string literal (see the ExecuteJavaScript documentation).

If you want to use jQuery, you need to use "window.jQuery" instead of "$". For example, you can call jQuery.noConflict() instead of $.noConflict()

Please have a look at the source code of the jQuery Ajax extension for CSHTML5 to see an example of loading and using jQuery.

Thanks.
Regards,
JS-Support

Re: Any\All jQuery causes Non-Translatable Function Exception: The function 'xxx' could not be translated.

Posted: Wed Sep 20, 2017 4:28 pm
by TaterJuice
JS-Support wrote:Hi,

"$" is a reserved keyword for the "ExecuteJavaScript" method. It is used to pass arguments to the string literal (see the ExecuteJavaScript documentation).

If you want to use jQuery, you need to use "window.jQuery" instead of "$". For example, you can call jQuery.noConflict() instead of $.noConflict()

Please have a look at the source code of the jQuery Ajax extension for CSHTML5 to see an example of loading and using jQuery.

Thanks.
Regards,
JS-Support


Perfect, thank you!
(Please feel free to move this to the Support forum, from bug reports - my apologies!)