2014-01-09 63 views
0

我有一个PHP页面,基于它的GET回声JSON数据。例如:阅读并将页面输出存储到另一个页面中?

HTTP://localhost/htdocs/includes/person_get.php ID [] = 1个& ID [] = 2

[{"id":"1","name_first1":"Daniel","name_last1":"Pendergast"},{"id":"2","name_first1":"Dennis","name_last1":"Pendergast"}] 

我想要做的就是阅读从另一个页面解码成一个数组。我怎样才能做到这一点?

回答

1

我会亲自提取出来,在检索的人的逻辑person_get纳入函数并在person_get和任何其他页面需要使用该逻辑中包含该函数。

如果您在调用它死心塌地,你可以使用file_get_contentsjson_decode

$data = json_decode(file_get_contents('http://localhost/htdocs/includes/person_get.php?id[]=1&id[]=2')); 

https://stackoverflow.com/a/2100310/2033671

+0

感谢。我之所以这样分开它,是因为我也希望能够通过AJAX以Javascript访问它。你能想出一种适用于PHP和JS的方法吗? –

0

看看jQuery和jQuery函数$.load()$.get()

使用jQuery(JavaScript的),你可以这样做:

$.get(
    'http://localhost/htdocs/includes/person_get.php', 
    { "id[]": [1, 2] }, 
    function(data) { 
     // data is your result array 
    } 
); 
相关问题