After dedicating the past two days to my work, I am still struggling to find a solution. Any assistance would be greatly appreciated. My current setup involves nodejs and Vue.
- I need help figuring out how to break out of an AJAX call when receiving a "No" result and stop the loop.
- I am encountering issues accessing the
userExist
array variable. - The same problem arises when trying to work with the
this.info['isthisUser']
Vue variable.
var thisUser = ["NY","NJ","CT","CA"]
var userExist = mycheck(thisUser)
console.log(userExist);
this.info['isthisUser'] = userExist;
console.log(this.info['isthisUser']);
function mycheck(val) {
var usCNT = val.length;
var array = new Array();
if (usCNT>0) {
for (var u=0; u<usCNT; u++) {
var checkThisUser = val[u];
$.ajax
({
type: "POST",
url: '/getStates',
data: { user: checkThisUser,},
success: function (data, msg) {
result = data ;
array.push(result);
if(result === 'No') {
alert('not exist');
}
})
}
}
return array;
};
console.log(userExist)
displays the following format:
[]
0: "No"
1: "No"
2: "No"
3: "Yes"
length: 4
__ob__: Observer {value: Array(4), dep: Dep, vmCount: 0}
__proto__: Array
console.log(this.info['isthisUser'])
shows the below:
[__ob__: Observer]
0: "No"
1: "No"
2: "No"
3: "Yes"
length: 4
__ob__: Observer {value: Array(4), dep: Dep, vmCount: 0}
__proto__: Array