I'm having issues with getting data from an AJAX file,
I am trying to change the datasource of a web app and the data source is originally created like this in javascript:
var ds = [
'Sarah',
'John',
'Jack',
'Don',
'Ben',
'Breem'];
Instead of hard-coding it in like this, I wanted to get it from an ajax file, and I have tried to do this:
var categories = $.ajax({
u开发者_运维问答rl: "js/ajax.php?projects=1",
async: false
}).responseText;
But it seems to be interpretting every character as a segment in the array, I tested with the exact same array and just echoed
[
'Sarah',
'John',
'Jack',
'Don',
'Ben',
'Breem']
I think I need to return it as an array, but I'm not sure how, should I be using like getJSON for this? Thanks!
UPDATE: I have managed to make it understand it as an array by surrounding the request with eval(), is this the right way to do it?
UPDATE: I have managed to make it understand it as an array by surrounding the request with eval(), is this the right way to do it?
Yes, that's the right way. Otherwise you will just get a string and since a string is basically an array of charcters, that's what you see.
精彩评论