The interface provided by the background is like this
I can’t request the data by writing like this, but I can by writing like this
How to break it
ringa_lee
It should be that codeAndName is undefined.
Print the passed parameters in one line between function and $http.post to know the problem
function
$http.post
console.log('pageNum---', pageNum); console.log('pageSize---', pageSize); console.log('codeAndName---', codeAndName);
I guess it’s undefined, let’s print it out first
undefined
Two questions, one is the undefined question mentioned above. Also, if your angular is a relatively new version, then the .success method has been cancelled, and .then() should be used.
$http.post(url,data).then(function(response){ //得到数据后的逻辑 })
Also, judging from your two pieces of code, it should take no more than a month for you to learn programming. Still need to work harder.
function loadData(codeAndName, pageSize, pageNum) { // 在这里对参数进行默认值设定,而不是在 success 里 codeAndName = codeAndName || ""; pageSize = pageSize || 10; pageNum = pageNum || 1; // 我猜这里要设置 isLoading = true,表示加载进行中 // 这样和下面的 $scope.isLoading = false 才对称 $scope.isLoading = true; $http.post(/*.....*/) .success(function(data) { $scope.isLoading = false; if (!data) { // do something while failing } else { // do something right; } }); }
It should be that codeAndName is undefined.
Print the passed parameters in one line between
function
and$http.post
to know the problemI guess it’s
undefined
, let’s print it out firstTwo questions, one is the undefined question mentioned above. Also, if your angular is a relatively new version, then the .success method has been cancelled, and .then() should be used.
Also, judging from your two pieces of code, it should take no more than a month for you to learn programming. Still need to work harder.