1

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({
  url: "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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.