Small note (i): Ajax passes an array and assigns the Ajax return data

Source: Internet
Author: User

When using Ajax to pass data, it is possible to pass multiple data, which can be used to pass data in such a way that the data is too large and mixed

$.ajax ({            type:' post ',            url:url,            data:{data:data, Content1:content1,  Content2:content2,content3:content3,...........},            success:function  (data) {                alert (data)            }        });

We can then wrap the data in the array before passing the data, but be aware that when defining an array, use the arr={} form

var arr= {}; var text= '; arr[' Content1 ']= ' value 1 '; arr[' Content2 ']= ' value 2 '; arr[' Content3 ']= ' value 3 '; arr[' Content4 ']= ' value 4 '; $.ajax ({type:' Post ', Url:url, Data:arr, async:  false,//set to synchronous operation to assign a value to a global variable successfullySuccessfunction(data) {
Text=data; } });

Alert (text)

The async:false in the code above is to set the Ajax pass default asynchronous operation to synchronous operation, so that the returned value can be assigned to text, run when the popup will output the returned content, if there is no async:false
, the popup is empty

Small note (i): Ajax passes an array and assigns the Ajax return 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.