简体   繁体   English

如何使用XAMPP本地服务器获取JSON / JSONP数据?

[英]How to get JSON / JSONP data using XAMPP local server?

I have set up a local server using XAMPP . 我已经使用XAMPP设置了本地服务器。 Now I want to get JSON / JSONP data from that server. 现在,我想从该服务器获取JSON / JSONP数据。

Side question: 附带问题:

Do I need to somehow upload the JSON file on the server? Or is there some Do I need to somehow upload the JSON file on the server? Or is there some PHP coding for that? IF yes, which? Do I need to somehow upload the JSON file on the server? Or is there some coding for that? IF yes, which? Do I need to somehow upload the JSON file on the server? Or is there some PHP coding for that? IF yes, which? coding for that? IF yes, which?

I have heard about some jQuery ajax call function, but it didnt work for me. 我听说过一些jQuery ajax调用函数,但是对我来说不起作用。 Any ideas? 有任何想法吗?

You have several way of doing that. 您有几种方法可以做到这一点。 if the result is not dynamic you just create a json file on server and get it using URL. 如果结果不是动态的,则只需在服务器上创建一个json文件并使用URL即可获取。

if you want to do it dynamic in response to web page sent to server you can use the built in PHP function json_encode. 如果要动态响应发送到服务器的网页,则可以使用内置的PHP函数json_encode。

Please follow php documenation for json_encode 请按照php文档中的json_encode

i don t think you need to do a lot of things. 我认为您不需要做很多事情。 json is a way to format data. json是格式化数据的一种方式。 you can do that returnin an output using json_encode() 您可以使用json_encode()在输出中返回

exemples and info at http://www.php.net/manual/en/book.json.php 示例和信息, 请访问http://www.php.net/manual/zh/book.json.php

一种方法是使用PHP中可用的json_encode()函数将JSON格式的数据发送到客户端,并通过提及dataType: json处理AJAX中的响应

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM