Analysis of problems with ajax requests for data, and problems with ajax requests for data
Use jquery and post to request data: JSON. stringify (data)
$.ajax({ type:"POST", async : false, url:"../../gzq/circle/deleteTeam", dataType:"json", contentType:"application/json; charset=utf-8", data:JSON.stringify(c), success:function(data){ console.log(data); }, error:function(error){ console.log(error); }});
Cause: in fact, if JSON. stringify (data) is not used, it will become a String concatenation, 'name = vinxent & age = 21', a bit similar to the get method. If JSON. stringify (data) is used, the json object -- "{name; 'vinxent ', age: 21}" will be transmitted }"
Therefore, in general scenarios, the get method does not require JSON. stringify, and the post method does.
AngularJS request Summary
$ Q usage of delayed loading (promise in angularJS)
.service('findXfzzShopInfo', ['$http', '$q', function($http, $q) { this.get = function(shopClassId, val) { var def = $q.defer(); $http({ url: '../../shop/findXfzzShopInfo?shopClassId=' + shopClassId + '&val=' + val, method: 'GET', cache: true }).then(function(resp) { def.resolve(resp.data); }).catch(function(err) { def.reject(err.data); }); return def.promise; };}])
To determine the environment, the request is encapsulated as a service and the $ q defer delayed loading is used.
Cache: true Configuration
When the request content remains unchanged for a long time, we can use this configuration to cache the request, reduce the server pressure, increase the page speed, and clear the cache when the page is closed. You can also configure the time after cahe.
When the request is 200, you find that the function fails.
What we will talk about here is not to configure responseType, but to return a list in the background during the get request. When there is a value, you will find that there is no problem at all, when there is no value, nothing will be returned in the background, and your responseType is json. At this time, the failed function is entered, so you are stuck in the background, you can return an object if you leave it empty in the background.
The above are the problems we have encountered in this ajax request. If you still have any questions you may not understand during your study, you can discuss them in the message area below. Thank you for your support for the help house.