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.