Data to be asynchronously transmitted:
Xml Code
....
<Action xsi: type = "basic: JavaScript" script = "index + = 1;"/>
....
Ajax asynchronous transmission code:
Js Code
Copy codeThe 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 in encode and unencode eventually leads to Data + replaced by spaces in the background Servlet, making index + = 1 in the script changed 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 codeThe Code is as follows:
Control names and values are escaped. Space characters are replaced by '+', and then reserved characters are escaped
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 Code
Copy 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.