这段代码工作正常,现在我总是得到一个“意外的令牌”
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
if (xmlhttp.responseText.search("url=") == 0){
$("#showMessage").after('<div class="message"><center>Copy your new URL:<input type="text" disabled="disabled" value="'+xmlhttp.responseText.substr(4)+'"</input><br /></center></div>');
else{
$("#showMessage").after('<div class="error">'+xmlhttp.responseText+'</div>');
}
}
}
这就是所谓的:
<input type="submit" id="btn-submit" value="Submit" onclick="javascript:createURL()"/>
(我也得到了“createURL未定义”,但我猜这是因为语法错误)
答案 0 :(得分:2)
您需要在else
之前使用右括号。
if (xmlhttp.responseText.search("url=") == 0){
$("#showMessage").after('<div class="message"><center>Copy your new URL:<input type="text" disabled="disabled" value="'+xmlhttp.responseText.substr(4)+'"</input><br /></center></div>');
} else{
$("#showMessage").after('<div class="error">'+xmlhttp.responseText+'</div>');
}
答案 1 :(得分:0)
if ... else
声明中存在语法错误
现在是:
if(){
...
//<< There should be a closing bracket for the if statement here
else{
...
}
但它应该是:
if(){
...
}
else{
...
}
或者如果if
或else
子句中的代码在一行上,您可以跳过括号:
if() ...;
else ...;