I have this annoying problem with ajax in JQuery. I have a function where I want to get prices from server for bunch of products. The problem is that I have a function that is not invoked on succes, but rather it works on its own. So what am I trying to do is simply run the function, that calls server and gets data, then it traverse through element and update prices for the products.
The problem is that I don't know how to make AJAX call simply return me that JSON string. I am unable to make succes function return response data.
function getdataJSON(url, data, method, type) {
$.ajax({
url: url,
method: method,
type: type,
data: "data=" + JSON.stringify(data) + "&ajax=1",
success: function (response) {
readataJSON(response);
},
// error: function (response) {
// errordataJSON(response);
// }
}
function readdataJSON(responseJSON) {
return responseJSON;
}
function myFunc(element) {
var url = "url_to_server";
var data = "product_types";
var type = "html";
var method = "GET";
var data = getdataJSON(url, data, html, method); // i want my prices here returned from server in JSON format, but data is always empty
decodedDATA = $.parseJSON(data);
// here goes functionality corresponding to element and retrived data
}
What am I doing wront or how can I make my function work as I described.
Thanks in advance.