2. The data cloud that does not use the cloud API may be because there is already a web version and commercial data.
3. The data cloud without cloud API needs to write its own data interface, that is, the client sends a request to receive and process it and generates json data for the client to interact with.
4. thanks to APICloud for providing new APP development methods.
Actually, it's not difficult. Just make a request with api.ajax. PHPer, the following demonstration uses PHP, and the database uses Mysql, JAVA Party or. Net party. Please code it yourself. ...
[Connect the database (the file is placed on the server), and the server outputs JSON]
& lt? Server-side programming language (abbreviation of professional hypertext preprocessor)
/*
* Configure connection database information
*/
$ host =' localhost// host
$ user =' root// database account number
$ password =“”; //database password
$ database =' test// database name
//Open the database connection
$ db = mysqli _ connect($ host, $ user, $ password, $ database);
//Judge whether the connection is successful.
if($db){
$ d B- & gt; query(" set names utf8 "); //Set UTF-8 encoding (unique encoding of JSON)
} Otherwise {
Echo' DATABASE _ CONNECTION _ DIE// Database connection failed.
Quit;
}
//sql query statement
$sql="select id,name,sex,age from person ";
$ result = $ d B- & gt; Query ($ SQL);
while($ row = $ result-& gt; fetch_assoc()){
$ person _ info[]= $ row; //Assign all the obtained data to the person_info array.
}
echo JSON _ encode($ person _ info); //output JSON
& gt
Copy code
Example of JSON output:
[{"id":" 1 ","Name ":"\u54c8\u5c3c ","Gender ":"\u7537 ","Age ":"22"}, {"id":"2 ","Name ":
Copy code
[Database SQL statement for testing]
-
-Database: `Test'
-
- -
-
-The structure of the table man.
-
If there is no Person, create a table (
Id' int( 1 1) is not empty.
Name' varchar(5) is not empty.
Sex' varchar(2) is not empty.
Age' int(3) is not empty.
Primary key (`id`)
)ENGINE = InnoDB DEFAULT CHARSET = utf8;
-
-Transfer the data in the table to individuals.
-
Insert Personal (Identity, Name, Gender, Age) values.
(1,' Hani',' Male', 22),
(2, "Xiao Chen", "female", 2 1),
(3,' Xiaobai',' Unknown',1);
Copy code
After that, the server outputs JSON, and the key point comes. ...
[End API uses api.ajax to read interface data]
& lt! DOCTYPE HTML & gt
& lthtml & gt
& lthead & gt
& ltmeta charset="utf-8 " >
& ltmeta name="viewport "
Content = "maximum-scale =1.0, minimum-scale= 1.0, user extensible =0, width = device width, initial-scale= 1.0"/ >
< title > test ;
& lt/head & gt;
& ltbody & gt
& ltbutton onclick = " showperson info()" & gt; Click on me to get data.
& lt/body & gt;
& ltscript type = " text/JavaScript " src = "../script/API . js " & gt; & lt/script & gt;
& lt script & gt
Function showPersonInfo(){
API . show progress(); //Displays the loading progress box.
//request data using api.ajax Please refer to the official documents for specific usage methods and parameters. Here, use the get method to demonstrate.
api.ajax({
URL:' http:/192.168.0.10/get.php',//If the address cannot be accessed, an error will be requested. Please fill in your own interface address.
Method: "get",
Cache: "false",
Timeout: 30,
Data type,' json',
},function(ret,err){
API . hidepression(); //Hide the loading progress box
if(ret){
for(var I = 0; I & ltret. Length; i++){
defined variable
html = ' & lt' br & gt'+' ID:“+ret[I]”。 id+' & lt;' Br & gt'+' Name:' +ret [i]. Name+'
Br>+' Gender:' +ret [I]. Sex+'
document . write(html);
}
} Otherwise {
Api.alert({msg: ('error code:'+err.code+'; Error message: "+err.msg+" Network status code: "+err.statuscode)});
}
});
}
& lt/script & gt;
& lt/html & gt;