Encountering difficulties in retrieving data from an AJAX file,
I am attempting to modify the data source of a web application originally defined in JavaScript as:
var ds = [
'Sarah',
'John',
'Jack',
'Don',
'Ben',
'Breem'];
Instead of hard-coding it, I aim to fetch it from an AJAX file. Here is what I have tried:
var categories = $.ajax({
url: "js/ajax.php?projects=1",
async: false
}).responseText;
It appears that each character is being interpreted as a separate array element. To test this, I echoed the exact same array:
[
'Sarah',
'John',
'Jack',
'Don',
'Ben',
'Breem']
I believe the data needs to be returned as an array. Would using getJSON be more appropriate for this task? Thank you!
UPDATE: Managed to resolve the issue by encapsulating the request with eval(). Is this method recommended?