Data to be asynchronously transmitted:
XML Code
....
<Action xsi: TYPE = "Basic: JavaScript" script = "index + = 1;"/>
....
Ajax asynchronous transmission code:
JS Code
Copy code The Code is as follows: var postdata = "input =" + escape (inputjson) + "& script =" + escape (XML) +
"& Feedgeneral =" + escape (feedgeneral );
XMLHttpRequest. Open ("Post", URL, true );
XMLHttpRequest. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
XMLHttpRequest. Send (postdata );
postdata is replaced by space in the backend servlet with Data + in encode and unencode, which changes index + = 1 in script to Index = 1; this leads to an endless loop of background Java code running scripts.
search online and find that Content-Type uses Application/X-WWW-form-urlencoded:
[from http://www.w3.org/tr/html401/interact/forms.html#h-17.13.4.1#write copy Code the code is as follows: Control names and values are escaped. space characters are replaced by '+', and then reserved characters are escaped as
described in [rfc1738], section 2.2: non-alphanumeric characters are replaced by '% hh ', A percent sign and two hexadecimal
digits representing the ASCII code of the character. line breaks are represented as "cr lf" pairs (I. E ., '% 0d % 0a ').
However, similar issues do not occur when you use form to submit a request. The default Content-Type of form is application/X-WWW-form-urlencoded:
JS CodeCopy codeThe Code is as follows: $ ('test '). innerhtml = "<form target = '_ blank' Id = 'test _ form' action = '. /gen_feed 'method = 'post'>"
+ "<Input type = 'text' name = 'input'/> <input type = 'text' name = 'script'/>"
+ "<Input type = 'text' name = 'feedgeneral '/> <input type = 'did' name = 'format' value ='" + this. feed_type + "'
/>"
+ "<Input type = 'submit 'value = 'gen'/> </form> ";
VaR test_form = $ ('test _ form ');
Test_form.elements [0]. value = inputjson;
Test_form.elements [1]. value = script;
Test_form.elements [2]. value = feedgeneral;
Test_form.submit ();
I have not found out where the problem is. I have forgotten it. Temporarily replace '+' in the script with '-', index + = 1; change to index-=-1; Haha, someone will see this generated weird script later, I don't know what I think, but now I can only do this.