This question already has an answer here:
I am really new to javascript. I have this code which takes the value from the autocomplete text box and get the names related to the text from the DB. That is done in the function myFunction
, this work as I expected. I have passed the data
to a variable called data_set
inside the ajax.
I want to get the data_set to use in another method as show in the code as getText
. But data_set is empty inside the getText
<input id="autocomplete" onkeyup="myFunction()" onkeypress="showIt()">
<script>
var data_set="";
function myFunction() {
var keywordx = document.getElementById("autocomplete").value;
var data_set="";
$.ajax({
type: "GET",
url: '/welcome/getResults/'+ keywordx,
data: {keyword:keywordx}, // appears as $_GET['id'] @ your backend side
success: function(data) {
// data is ur summary
//$('#refresh_this').html(data);
data_set = data;
console.log(data_set);
}
});
}
function getText() {
console.log(data_set);
}
Aucun commentaire:
Enregistrer un commentaire