I have a task that involves calling a REST API and getting the response. Currently, I am able to achieve this by directly making the AJAX call, which works perfectly fine. However, I now need to refactor this process into a function where I can pass two parameters that will be used in the URL. The goal is to return the response from this function so that it can be utilized in other classes.
function fetchData(param1, param2) {
$.ajax({
url: "BaseURL" + param1 + "/" + param2
}).then(function(data) {
if (data.test == null)
self.prop1(data.test);
if (data.test2 !== null)
self.prop2(data.test2);
if (data.test3 !== null)
self.prop3(data.test3)
});
}
Can you please provide any suggestions on how to approach this? Let me know if you require any additional information from my end.