[英]JavaScript which inside JSP doesn't work when I used java tag
$( document ).ready(function() {
console.log( "ready!" );
var ilceler = "${ilceler}";
});
It doesn't print "Ready!" 它不会显示“ Ready!”。 to console.
进行控制台。 When I debug with chrome, I saw
当我用chrome调试时,我看到了
$( document ).ready(function() {
console.log( "ready!" );
var subChildList = "";
ilceler = JSON.parse(" [
{"id":"xx","tag":"xx","name":"xxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxxxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxxx","fatherid":"66","fathertag":"il"},
{"id":"x","tag":"xx","name":"xxx xxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xx\/xxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxx","fatherid":"66","fathertag":"il"},
{"id":"xx","tag":"xx","name":"xxxx","fatherid":"66","fathertag":"il"}]");
});
My data is true, but why this function doesn't work. 我的数据是正确的,但是为什么此功能不起作用。 Note: My data includes UTF-8 characters.
注意:我的数据包含UTF-8字符。 Note2: I can work with string instead of json.
注意2:我可以使用字符串代替json。
var a = ${tag}
console.log(a) >> "It's my tag"
I seems to me that you need to remove the quotes surrounding your variable. 在我看来,您需要删除变量周围的引号。
So it should be 所以应该
var ilceler = ${ilceler};
The JSP/JSTL interpreter will leave these quotes and hence your object will be regarded as a String value instead of a JSON object. JSP / JSTL解释器将保留这些引号,因此您的对象将被视为String值而不是JSON对象。 Also if your second output is the output in the browser you can see it's not valid JSON.
另外,如果第二个输出是浏览器中的输出,则可以看到它不是有效的JSON。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.