dongyan7876 2017-03-21 18:30
浏览 106
已采纳

Web服务中的JSON

I know that JSON can be used between 2 web servers, for example facebook API provides some infos using aFile.json so my website need to handle it using PHP's json_decode() function,

the problem that I can't imagine any pratical situation wherein we can use it between a server and his client to exchange data. If the client request for some data, the server will use either SQL to retrieve them from a database or a JSON recieved file or whatever else... but finally he will respond only by an HTML file (& probabely some images) so the client's browser can interpret it,

Am I wrong and the JSON files can be sent to the client ? then why ? I readed also that JSON is used to communicate between PHP and javascript in the same server, can you give me an example of this case ?

  • 写回答

2条回答 默认 最新

  • dt1888 2017-03-21 18:50
    关注

    You can think about it in this way:

    1. You go to the website X, and your browser (client) sends request to the server, for particular page. In this case, server will respons with HTML page wich will be rendered by your browser to you.
    2. You already are on website X, your browser already rendered a page for you, and now you have input with newsletter subscription, you put your e-mail in this input and click 'subscribe'. Here one of the scenarios is that JavaScript will post your e-mail to the server using JSON-format, and server will respond to the JavaScript associated with your HTML some confirmation (also in JSON-format), which will be displayed for you.

    This second scenario might be used in order to avoid reloading the page which is already render for You.

    You can go to developer tools in your browser, you can display section network, and You can observe different HTTP messages which are sent back and forth between client and server.

    For more information I suggest reading https://developer.mozilla.org/pl/docs/Web/HTTP because they have nice documentation regarding HTTP there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料