when i run my code it show a script error dialog
"Error -Script error ,URL - http://www.bing.com/api/maps/mapcontrol?callback=OnLoad"
OnLoad is function which i call to initialize the map
Url i used to get map in my html file -
<script type='text/javascript' src='http://www.bing.com/api/maps/mapcontrol?callback=OnLoad' async defer></script>
Two things to try. First make sure your network can reach the http://bing.com website. Second, make sure you have a function call OnLoad that is accessible to the map control to call. Verify spelling and that it al control doesn't try and call this function before it is available. Try adding async defer to your script tag and this will allow your other code to load a bit faster.
Related
Basically, I'm trying to invoke a basic custom JS function from C# (for learning purposes) and whenever I try to run that function it says that it could not be found even though I have added the .js file containing the function to the Index.html file as a script
The .js file
function my_function(message)
{
console.log("Message: "+message)
}
The index.html file's body
<body>
<div id="app">Loading...</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
Reload
<a class="dismiss">🗙</a>
</div>
<script src="_framework/blazor.webassembly.js"></script>
<script src="JS/example.js"></script>
</body>
The file trying to invoke the function
#code
{
public async Task myMethod()
{
await js.InvokeVoidAsync("my_function", "Custom message");
}
}
I checked the file's name, it's exactly as written, even html prompts to write the name, it's the exact same one. The applications runs, but whenever I try to access the part that uses the method, I get a long error with the main part of being this:
Could not find 'my_function' ('my_function' was undefined)
Any help would be extremely appreciated, and if anyone has seen my previous posts, ik that I'm probably asking way too much but I genuinely tried everything I could find, but nothing worked
You'll need define your function as a JavaScript property like this:
window.my_function = (message) => {
console.log("Message: " + message);
};
Then you can call it with the IJSRuntime like this:
await js.InvokeVoidAsync("my_function", "Custom message");
I have an aspx page using only inline C# without a codebehind.
Running from Visual Studio it works, however adding the aspx file to the wwwroot of my local machine gives the message
Compiler Error Message: CS1513: } expected
If I rearrange the code to have the method above the code the message is instead
CS1519: Invalid token 'try' in class, struct, or interface member declaration
I expect it is something to do with server configuration, though I don't really know where to start.
The issue only occurs if there is methods, removing method1 from the below results in correct running.
This is the minimum entire file I was able to cause the error with
html
<%# Page Language="C#" %>
<%
try
{
string message = "Text";
Response.Write(method1(message));
}
catch
{
Response.Write("Err");
}
string method1(string source)
{
return source;
}
%>
If you're embedding code directly on the aspx page, that code still has to go in a method. Ex:
<%# Page Language="C#" %>
<%
void Page_Load(Object sender, EventArgs e)
{
try
{
string message = "Text";
Response.Write(method1(message));
}
catch
{
Response.Write("Err");
}
}
string method1(string source)
{
return source;
}
%>
By the way - we don't typically put C# code directly in the .aspx file. That's what the code behind system is for.
And we don't typically write directly to the response. It's hard to control where the markup will end up. In Web Forms, it's better to declare a control on the page and then add markup to that (or show/hide controls). Of course if we're going to talk about doing things well - then don't use Web Forms in the first place. It's a dead technology.
I have messed around with the Visual Studio project, running on an earlier version of .NET/C# yields the following error, It seems possible that this is the actual problem I have had
Error CS8059 Feature 'local functions' is not available in C# 6. Please use language version 7.0 or greater.
I am unsure why it thinks method1 is a local function and details are hard to come by.
Edit: To solve my problem I put the method in script tags instead of embedded code blocks. The methods then could be used from the embedded blocks and the script tag.
<script runat="server">
string method1(string source)
{
return source;
}
<script>
I am having the strangest error and it's driving me up the wall. At the moment I have the following two bundles...
var jquery = new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"
, "~/Scripts/jquery-ui-{version}.js"
, "~/Scripts/materialize/materialize.js"
, "~/Scripts/knockout-{version}.debug.js"
, "~/Scripts/knockout-{version}.js"
, "~/Scripts/jquery.signalR-{version}.js");
var jsfiles = new ScriptBundle("~/bundles/Assets/js")
.IncludeDirectory("~/Assets/js", "*.js", true);
bundles.IgnoreList.Ignore("~/Scripts/knockout-{version}.js", OptimizationMode.WhenDisabled);
Within the ASSETS folder there is the following file
jquery-ui-1.10.3.custom.min.js"
When I debug and run locally everything is fine. However when I turn on following
BundleTable.EnableOptimizations = true;
The jquery-ui file mentioned is throwing the following error...
Uncaught TypeError: Illegal invocation
Which relates to this block of code
return u?n.isFunction(u[e])&&"_"!==e.charAt(0)?(i=u[e].apply(u,o),i!==u&&i!==t?(s=i&&i.jquery?s.pushStack(i.get()):i,!1):t):n.error("no such method '"+e+"' for "+r+" widget instance")
:n.error("cannot call methods on "+r+" prior to initialization; attempted to call method '"+e+"'")})
:this.each(function(){var t=n.data(this,f);});
I don't even know where to start debugging it? Could the minification engine be doing something?
From memory, javascript resourced with .min in the filename are automatically excluded from bundling, so referencing the unminified version of the JQuery UI document should fix it (or alternatively, but not recommended - remove the .min from your existing filename.
I'm trying to invoke an image with infobox and infoboxImage. Here is what I have....
|image = {{#invoke:InfoboxImage|InfoboxImage|image={{{image|}}}|size={{{image_size|}}}|upright= {{{image_upright|1}}}|alt={{{alt|}}}}}
And I get the following error on my index.php?title=Module:InfoboxImage&action=submit#mw-ce-l1 page
Script error: Lua error at line 1: unexpected symbol near '|'.
What do I need to do to get this working?
Here is my LocalSettings.php for Scribunto:
require_once "$IP/extensions/Scribunto/Scribunto.php";
#$wgScribuntoDefaultEngine = "luastandalon"';
So you're adding template syntax like {{{image|}}} in a module page? Why?
I doubt you really need to handle such a Lua module for your wiki. However, if you really want to copy the Lua-powered infobox templates of other wikis, make sure you import them with Special:Import and select the recursive import checkbox.
Hopefully you'll then have all the modules you need without fiddling with them.
I figured out I cannot load one script library from another easily:
module.csx
string SomeFunction() {
return "something";
}
script.csx
ExecuteFile("module.csx");
SomeFunction() <-- causes compile error "SomeFunction" does not exist
This is because the compiler does not know of module.csx at the time it compiles script.csx afaiu. I can add another script to load the two files from that one, and that will work. However thats not that pretty.
Instead I like to make my scripthost check for a special syntax "load module" within my scripts, and execute those modules before actual script execution.
script.csx
// load "module.csx"
SomeFunction()
Now, with some basic string handling, I can figure out which modules to load (lines that contains // load ...) and load that files (gist here https://gist.github.com/4147064):
foreach(var module in scriptModules) {
session.ExecuteFile(module);
}
return session.Execute(script)
But - since we're talking Roslyn, there should be some nice way to parse the script for the syntax I'm looking for, right?
And it might even exist a way to handle module libraries of code?
Currently in Roslyn there is no way to reference another script file. We are considering moving #load from being a host command of the Interactive Window to being a part of the language (like #r), but it isn't currently implemented.
As to how to deal with the strings, you could parse it normally, and then look for pre-processor directives that are of an unknown type and delve into the structure that way.
Support for #load in script files has been added as of https://github.com/dotnet/roslyn/commit/f1702c.
This functionality will be available in Visual Studio 2015 Update 1.
Include the script:
#load "common.csx"
...
And configure the source resolver when you run the scripts:
Script<object> script = CSharpScript.Create(code, ...);
var options = ScriptOptions.Default.WithSourceResolver(new SourceFileResolver(new string[] { }, baseDirectory));
var func = script.WithOptions(options).CreateDelegate()
...