app Request Server json Data Instance Code

  • 2021-08-17 00:58:40
  • OfStack

Request server json data format code, as follows;


var url=obj.serUrl; // This is the path of the requesting server url Put your own request path; 
var data = {//date Inside carries the parameter, according to the server request fills in the parameter, sees clearly is the string type, or the integer type. 
action:'getUser',
username:loginInfowode,
password:passwordwode
};
// The following is the entry ajax Request server data; 
mui.ajax({
    type:"post",// Request format, divided into post/get
    url: url,// Path, write that on it 
    async: true,
    data:data,//data Parameter 
    dataType: "json",// Request data type. Have json , jsonp Two kinds; 
    jsonp: "jsoncallback",
    timeout: 1000,// Request delay time 
    success: function(data) {// Request successful entry data
   console.log(" The results obtained after successful login are: "+(JSON.stringify(data)));// Converts to an object type because json Data must be converted to an object before key-value pairs can parse data. 
// Write request information and logical requirements here; 
    },
    error: function(xhr, type, errorThrown) {// Wrong function here 
     callback("error!"); 
    }
   });

This is the correct request format for HBulider, It can be successfully analyzed to obtain data, and it is no problem to complete the request for json data. For beginners, it is always not wrong to learn more. Those who are interested can also be encapsulated, and the ajax request is encapsulated into an js file. Then, when a certain interface needs to call server data, it is simple and clear to request directly, which is convenient and concise, and has high maintainability in the later period. If you have any questions, you can contact the blogger, hoping to help everyone, thank you! .


Related articles: