Earlier, I had a problem getting the result of my Ajax call and operating on it without doing an asynchronous callback. What I wanted to do was assign the result of my ajax call to a variable so I could parse through it and return a result. After a little searching, I found this result.
1
| var result = $.ajax({url: "/my_relative_path", data: {param1: value, param2: value}, async: false}).responseText; |
Please note that because responseText returns a string, if your Ajax response includes JSON formatted objects, you need to use eval to convert them to objects.
2
| var result_objects = eval(result); |
In my case, I was returning a list of parameter id’s that matched some form fields I need to to change the style of. So, I created a for loop and looped over the objects in my array.
ajax, asyncrhronous, http, JQuery, response, synchronous