Jquery creates a JSON object using a JSON string, jqueryjson

Source: Internet
Author: User

Jquery creates a JSON object using a JSON string, jqueryjson

<Html> <body> 

Convert the json object in jquery to a normal string

The returned value of serialize () is a string.
SerializeArray () This method returns a JSON object instead of a JSON string. You need to use plug-ins or third-party libraries for string-based operations.
In jquery1.4API, a json object is converted into a string.

Example
Description:
Obtain the Form Content and insert it into the webpage.

HTML code:
<P id = "results"> <B> Results: </B> </p>
<Form>
<Select name = "single">
<Option> Single </option>
<Option> Single2 </option>
</Select>
<Select name = "multiple" multiple = "multiple">
<Option selected = "selected"> Multiple </option>
<Option> Multiple2 </option>
<Option selected = "selected"> Multiple3 </option>
</Select> <br/>
<Input type = "checkbox" name = "check" value = "check1"/> check1
<Input type = "checkbox" name = "check" value = "check2" checked = "checked"/> check2
<Input type = "radio" name = "radio" value = "radio1" checked = "checked"/> radio1
<Input type = "radio" name = "radio" value = "radio2"/> radio2
</Form>

JQuery code:
Var fields = $ ("select,: radio"). serializeArray ();
JQuery. each (fields, function (I, field ){
$ ("# Results"). append (field. value + "");
});... The remaining full text>

How does Jquery convert an object into a json string?

");??}??}); The running result is: Failed. Please try again later! No function is redirected to the background.
I debugged jQuery. toJSON (obj) and removed it to the background function.
The data sent to the server. Will be automatically converted to the request string format. The GET request will be appended to the URL. View the description of the processData option to disable automatic conversion. The format must be "{key: Value. If it is an array, jQuery automatically corresponds to the same name for different values. For example, {foo: ["bar1", "bar2"]} is converted to '& foo = bar1 & foo = bar2 '. If the value is an Array, jQuery creates a traditional setting based on multiple consecutive values with the same key value.
You do not need to convert it here. Change your code
Data: obj. Try again.

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.