This time I will bring you what problems you will encounter when requesting data with ajax. What are the precautions for ajax requesting data? Here are practical cases, let’s take a look.
Use jquery,post request data: where to use 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); } });
angularJSRequest some summary
$qThe use 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; }; }])
cache: true configuration
When the request content has not changed for a long time, we can use this configuration to cache the request, reduce the pressure on the server, and increase the speed of the page. This cache can be cleared when the page is closed. And the time can also be configured behind the cache.When the request is 200, you find that the failed function is used
What I want to talk about here is not to configure the responseType, but when I get the request in the background Return a list. When there is a value, you will find that there is no problem at all. When there is no value, the background returns nothing, and your responseType is json. At this time, the failed function enters, so the background still cheats you, and The background will negotiate and return an object to you when it is empty. I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:jQuery selector gets all parent elements and following elements at once
How about jquery+ajax Implement data update
Realize jquery to load data immediately on the startup page
Use jquery to operate the text content of the input box
The above is the detailed content of What problems will you encounter when requesting data with ajax?. For more information, please follow other related articles on the PHP Chinese website!