使用AJAX获取JSON数据并转换为字符串数组

I'm trying to get my data into an array of strings so that I can use it as a dataset for jquery autocomplete. What I'm getting now is an array of objects, which I don't think will work.

Jquery on my main page:

$.get("get_schools.php", function(data) {
               var results = jQuery.parseJSON(data);
               alert(results);
});

This results in data in the format of: [object Object],[object Object],[object Object]

On get_schools.php: I query a database and the return the results to an array called $displaynames. Then:

echo json_encode($displaynames);

Which looks like: [{"DisplayName":"XXXX Street Middle School"},{"DisplayName":"XXXXX Schools"},{"DisplayName":"XXXX Elementary School"}

UPDATE: this question has been flagged as a possible duplicate, but the other question pertains to getting a property of an object. i wasn't attempting to get a property of an object. i was attempting to convert an object array to an array of strings. i needed the property names as well as the values in the result. the other question only returns the values.

查看全部
doudanglang5826
doudanglang5826
2014/08/01 15:17
  • php
  • ajax
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复