JS serialized array for AJAX submission data

Source: Internet
Author: User

But we are going to commit with AJAJX similar to: Array (' id ' =>12,data = = Array (' A ' =>1, ' B ' =>2) '); When the data of a two-dimensional array, the direct AJAX submission background is not received, and requires special handling:
Only two-dimensional array data can be processed here, and multidimensional needs to be done in loops or recursively
function Serialize_data (obj) { var str = '; for (var i in obj) { if (typeof (Obj[i]) = = = "Object") {for (var s in Obj[i]) { str = str + i+ ' [' + S + '] ' + ' = ' + O Bj[i][s] + ' & '; } } else{ str = str + i + ' = ' + obj[i] + ' & '; } } return encodeURI (str);}

  

is actually a URL request similar to this:

http://192.168.0.63/index,php?id=12&data[a]=1&data[b]=2

When used for a request, you can actually use:

var str = uriencode (' id=12&data[a]=1&data[b]=2 ');

And then you can use STR to post or get the way it happens.

JS serialized array for AJAX submission data

Related Article

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.