Ajax Asynchronous Data Transmission

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.