简体   繁体   中英

Servlet not retrieve parameters from AJAX call

I used AJAX to call an action and pass parameters, the AJAX call occurs from xsl page and its as follows:

xmlHttp.open("GET","examcont?action=AJAX_SectionsBySessionId&sessionId="+sessionId,true);

I decided to put the amp; after & as xsl raises this error when I removed it:

The reference to entity "sessionId" must end with the ';' delimiter

the problem is that the action is unable to read the parameter sessionId however I tried the same action URL but without the amp; and the action reads the parameter successfully

The problem seems to be that the & represents & in the style sheet but gets expanded/escaped to & again during output (because it is HTML/XML). You may try to use the following in XSL to avoid escaping:

xmlHttp.open("GET","examcont?action=AJAX_SectionsBySessionId<xsl:text disable-output-escaping="yes">&amp;</xsl:text>sessionId="+sessionId,true);

However, note that - if you happen to let your XSL run in the browser - this does not work (although it is correct XSL and it should) on Firefox according to https://bugzilla.mozilla.org/show_bug.cgi?id=98168 .

As portable alternative, you can use the following which avoids mentioning & by inserting it at runtime with what you might call "Javascript-escaping":

xmlHttp.open("GET","examcont?action=AJAX_SectionsBySessionId"+String.fromCharCode(38)+"sessionId="+sessionId,true);

Also have a look at similar question with deeper discussion and other options using a html entity in xslt (eg &nbsp;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM