AJAX submits textarea text data

Source: Internet
Author: User

A simple question, find for a good while, leave a lesson in the time

In the beginning I used $ ("#textareaContents"). Text (); The text content, then remembered to textarea belong to form form, although <textarea name= "desc" cols= "rows=" "5" id= "desc" ></textarea> His writing is a closed (just like <div></div>) label, but the same as other form forms when getting text field values. val () get

Use $ (' #textareaContents '). Val (); Sure enough to get the value of the textarea.

var textareacontents = $ (' #textareaContents '). Val ();


In addition, when submitting to the background with Ajax, $.ajax ({
URL: "Userassess",
Type: "Post",
data:{textareacontents:textareacontents},//the ID of the first textareacontents value text box, submitted in jquery mode Ajax, this ID must be
DataType: "JSON",
Success:function (data) {}

According to the above Ajax submission, if you get the value of this textarea in the background, even if the text does not need to change the Chinese

No such transcoding is required, string textareacontents= new String (Request.getparameter ("textareacontents"). GetBytes ("Iso8859-1"), "Utf-8 ");

Directly with string textareacontents = Request.getparameter ("textareacontents"); it's okay.

TIP: Returns the JSON data don't forget to specify the return type Response.setcontenttype ("Application/json;charset=utf-8") in the background;

But if you submit a Chinese or ordinary href to a common form, you need to press the above transcoding.



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.