Reputation: 18892
I have a servlet that I want to send javascript via ajax call:
private String returnImage(String img, String imgFailOver) {
String str="<img src='http://Foo.com/images/"+img+".jpg' onError='this.onerror = null; this.src=\""+imgFailOver+".jpg\";' height='500' width='500'/><br/>";
return str;
}
Basically trying to have servlet send this:
<img src="image.png" onError="this.onerror=null;this.src='/images/noimage.gif';" />
From this SO doc.
My question/ problem is why do the escaped double quotes in servlet not register (get ignored) on the webpage?
PS- I'm tagging Java and Javascript b/c I'm not sure what side to fix this on?
Upvotes: 0
Views: 407
Reputation: 15250
You need to put "
instead of \"
. The HTML parser in the browser is unable to read \"
, this is a Java double quote escape.
Upvotes: 1