I want to have a simple function where i can insert a sqlQuery and get a database answer in json-format like this:
function ExecuteQuery(query){
$.post("sql.php", { "query": query },
function(data){ return data; },
"json");
}
The response i get is undefined, I think i have misunderstood something quite basic but i don’t know what, can anybody give me a hint?
The problem is that you want something you cannot have 🙂 Instead of thinking in terms of a function that returns a value, write yourself a function that takes another function as an argument and calls it when the data is available.
Now, when you call that function, you’ll pass it a function that can take the server response and do something with it.