Collection of request code based on apicloudAJAX and apicloudajax

Source: Internet
Author: User

Collection of request code based on apicloudAJAX and apicloudajax

Get Request Code:

Api. ajax ({url: 'http: // m.weather.com.cn/data/101010100.html' // WebService interface of the weather forecast website}, function (ret, err) {if (ret) {api. alert ({msg: JSON. stringify (ret)});} else {api. alert ({msg: JSON. stringify (err )});};});

POST request-Form submission:

Api. ajax ({url: 'http: // www.xxx.com/path/form', method: 'post', dataType: 'text', // if this parameter is not set, jsondata: {values: {name: 'devlp ', password: '000000'} // key-Value Pair }}, function (ret, err) {if (ret) {api. alert ({msg: JSON. stringify (ret)});} else {api. alert ({msg: JSON. stringify (err )});};});

POST request-upload a single file or multiple files in a file group:

Api. ajax ({url: 'http: // www.xxx.com/path/upload', method: 'post', data: {files: {myfile: 'filepath'} // filepath is from any file in the ios or Android file system. You can set multiple files, or even file arrays, such as files: {myfile: 'filepath', myfile1: 'filepath1 '}, or files: {'myfile []': ['filepath', 'filepathh1 ']}, function (ret, err) {if (ret) {api. alert ({msg: JSON. stringify (ret)});} else {api. alert ({msg: JSON. stringify (err )});};});

POST request-submit binary stream:

api.ajax({url: 'http://www.xxx.com/path/body',method: 'post',data: {body:'textbits'}},function(ret,err){if (ret) {api.alert({msg:JSON.stringify(ret)});} else {api.alert({msg:JSON.stringify(err)});};});

POST request-submit file stream:

Api. ajax ({url: 'http: // www.xxx.com/path/body', method: 'post', data: {stream: 'filepath' // filepath any file from the ios or Android file system }}, function (ret, err) {if (ret) {api. alert ({msg: JSON. stringify (ret)});} else {api. alert ({msg: JSON. stringify (err )});};});

POST request-Multipart-Data, submit the file and text fields together:

api.ajax({url: 'http://www.xxx.com/path/multipart',method: 'post',data: {values:{name: 'devlp', password: '123456'},files:{file: 'fs://test.png'}}},function(ret,err){if (ret) {api.alert({msg:JSON.stringify(ret)});} else {api.alert({msg:JSON.stringify(err)});};});

POST request-display upload progress:

Api. ajax ({url: 'http: // www.xxx.com/path/multipart', method: 'post', report: true, data: {values: {name: 'devlp ', password: '2016'}, files: {file: 'fs: // test.png '}}, function (ret, err) {if (ret) {if (0 = ret. status) {// loading ('Progress: '+ ret. progress);} else {api. alert ({msg: 'upload successful: \ n' + JSON. stringify (ret)}) ;}} else {api. alert ({msg: JSON. stringify (err )});}});

[End API uses api. ajax to read interface Data]

<! Doctype html> 

The above collection of request code based on apicloudAJAX is all the content shared by Alibaba Cloud xiaobian. I hope you can give us a reference and support for the customer's house.

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.