hello all i have this code
var temp;
if(method==1)
  temp = $(\"#Words\").val();             //get the words from textbox
else{
  $.getJSON(\"http://localhost/mi         
        
it's because getJSON is ajax request, not synchronous. Try this
var temp;
if(method==1) {
  temp = $("#Words").val();             //get the words from textbox
  proc(temp);
} else {
  $.getJSON("http://localhost/mine/test.js", function(data) {
      temp=data.Words;
      proc(temp);
  });
}
function proc(data){
    //do something with temp...but temp is undefined after the execution of else
}