我还是Javascript的新手.我正在开发一个简单的页面,我单击一个按钮来获取servlet上的值并显示它.它运作良好,除非我在按钮上点击疯狂.有时,显示的结果为null.
我想知道这是否是由同时调用相同的以下函数引起的:
function loadXMLDoc2(retr) {
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
$("#" + retr).button('option', 'label', xmlhttp.responseText);
// document.getElementById(retr).innerHTML=xmlhttp.responseText;
}
}
var param = "cmd=" + encodeURIComponent(retr);
document.getElementById("TOP_LEFT").innerHTML = param;
xmlhttp.open("GET","/WebFront/Asynclet?" + param,true);
xmlhttp.send(null);
}
Run Code Online (Sandbox Code Playgroud)
Javascript是线程安全的吗?如果没有,我如何同步或隔离对此方法的调用?
我有一个包含特殊unicode字符串的数组:
var a = [
["a", 33],
["h\u016B", 44],
["s\u00EF", 51],
...
];
Run Code Online (Sandbox Code Playgroud)
当我遍历这个数组时:
for (i=0;i<a.length;i++) {
document.write(a[i][0] + "<br />");
}
Run Code Online (Sandbox Code Playgroud)
它打印带有重音的字符:
a
hù
sô
...
Run Code Online (Sandbox Code Playgroud)
而且我要:
a
h\u016B
s\u00EF
...
Run Code Online (Sandbox Code Playgroud)
我怎样才能在Javascript中实现这一目标?
我正在尝试使用aspectj-maven-pluginmaven项目.在编译时,我得到:
Syntax error, annotations are only available if source level is 5.0
Syntax error, annotations are only available if source level is 5.0
Syntax error, annotations are only available if source level is 5.0
Run Code Online (Sandbox Code Playgroud)
但是,我在我的pom.xml中设置了以下内容:
<project.build.source>1.6</project.build.source>
<project.build.target>1.6</project.build.target>
Run Code Online (Sandbox Code Playgroud)
我有一些依赖:
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?谢谢.
解
我在我的pom.xml中添加了以下内容,现在它可以工作:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test-compile</goal>
</goals>
<configuration>
<source>${project.build.source}</source> <- Addition
<target>${project.build.target}</target> <- Addition
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud) 输入字段通常与表单相关联,但我想在简单的Javascript/HTML页面中使用它们.我不需要表格.我发现我的HTML页面没有问题,但是我不知道有任何危险或不良做法吗?我只是不希望我的页面出错.
(基本上,我的页面中的字段可以根据其他字段中的值启用或禁用Javascript)
我正在为Javascript代码编写一些测试,我需要在遇到错误时在编译过程中转储一些消息.
System.out.println()在Javascript中有没有相当于Java的东西?
PS:我还需要在实现测试时转储调试语句.
UPDATE
我在包含所有合并测试的文件上使用maven插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.mozilla.javascript.tools.shell.Main</mainClass>
<arguments>
<argument>-opt</argument>
<argument>-1</argument>
<argument>${basedir}/src/main/webapp/html/js/test/test.js</argument>
</arguments>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
更新II
我试过了console.log("..."),但我明白了:
js: "src/main/webapp/html/js/concat/tests_all.js", line 147:
uncaught JavaScript runtime exception: ReferenceError: "console" is not defined
Run Code Online (Sandbox Code Playgroud)
我正在测试的代码是一组函数(比如在库中).我正在使用QUnit.
我需要将Java字符的十六进制代码生成为字符串,并在以后再次解析这些字符串.我在这里发现解析可以执行如下:
char c = "\u041f".toCharArray()[0];
Run Code Online (Sandbox Code Playgroud)
我希望像Integer.valueOf()这样更优雅的东西进行解析.
如何正确生成十六进制unicode?
我一直在挖掘文档,但是我没有找到一个指令来定义一个图像的标记名称Dockerfile.但是有一个可用于命令行.
假设我创建了FROM另一个图像的图像,我不希望它具有相同的名称.我该怎么办?
我正在使用维基百科中提供的文档在集群模拟器应用程序中实现Paxos .不幸的是,它留下了几个可以解释的门,并没有提供关于关键实施问题的大量信息.目前还不清楚和不完整.
Paxos不会进入无限循环吗?我想如果一个人无法与至少一个法定数量的节点通信,就不应该发起Paxos.
什么是"它接受的最后价值"?来自提议者的任何先前提案编号是什么?在这种情况下,'实例'究竟是指什么?
在阶段1a:是否包含与准备消息达成一致的值,或者是否延迟到接受!信息?或者它确实重要?
在阶段2a:' 如果任何接受者已经接受了值,则领导者必须选择具有最大提议号N '的值.
这里有什么价值?是提案编号吗?我不相信,但这句话不清楚.
在阶段2a:'否则,提议者可以自由选择任何值'.这是什么意思?什么价值?对于提案号码?
Paxos似乎依赖于增加的N(提案号)值来运作?它是否正确?
维基百科条目不讨论节点在开始参与Paxos之前应该设置的初始值.这些是什么?
PS:我没有足够的声誉来创建'Paxos'标签(任何志愿者?)
javascript ×6
java ×3
unicode ×2
annotations ×1
aspectj ×1
char ×1
character ×1
compile-time ×1
docker ×1
docker-image ×1
dockerfile ×1
forms ×1
hex ×1
html ×1
input-field ×1
integer ×1
node-gyp ×1
node.js ×1
npm ×1
null ×1
overflow ×1
parsing ×1
paxos ×1
println ×1
synchronized ×1
system.out ×1
tags ×1
underflow ×1
windows-10 ×1