AJAX asynchronous transmission of data issues _ajax related

Source: Internet
Author: User
The data to be transmitted asynchronously:
XML code
....
<action xsi:type= "Basic:javascript" script= "index + + 1;" />
....
Ajax Asynchronous Transfer code:
JS Code
Copy Code code 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 resulting in the background servlet to get Data + is replaced by a space, so that the script in the index = 1, changed to index = 1, which causes the background Java code in the run script appears dead loop.
Search on the Internet, found Content-type use application/x-www-form-urlencoded after:
[From http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1] wrote
Copy Code code as follows:

Control names and values are escaped. Space characters are replaced by ' + ', and then reserved characters, are 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, using form to submit a request without a similar problem will not occur, and the form default Content-type is also application/x-www-form-urlencoded:
JS Code
Copy Code code 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= ' hidden ' 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 ();

Still do not find out where the problem is, temporarily make a memo. For the time being, the script ' + ' is replaced with '-', index = 1; change to index-= 1; hehe, someone later saw this automatic generation of strange script, do not know how to feel, but now can only be so.

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.