In the jquery example , is there anyway to use the suggest variable outside this $.ajax function?
$.ajax({
type: "POST",
url: "http://localhost/file/fetch.php",
data: {
"dataA": string
},
cache: false,
success: function(data) {
var Suggest = JSON.parse(data);
}
});
For example i want to use the suggest variable outside like this i first have to somehow make it into a global variable to use it anywhere i want is there any easy method to achieve this?
for (var i = suggest.length - 1; i >= 0; i--) {
for (var j = 0; j < arrString.length; j++) {
if (suggest[i] === arrString[j]) {
suggest.splice(i, 1);
}
}
}
And i also want to use the variable like this.
var suggestKey = "Suggested item";
var suggestArray = [];
obj[suggestKey] = suggest;
suggestArray.push(obj);