简体   繁体   English

如何在JS的服务器本地页面上传递从PHP页面获得的数据?

[英]How to pass the data obtained from the PHP page on the server's local page in JS?

I have an HTML 5 page that you can use offline. 我有一个HTML 5页面,您可以离线使用。 When this page is online you should connect to a PHP page (the 'I've already done) with a login and receive response in 1 string and 2 integers. 当此页面在线时,您应该使用登录名连接到PHP页面(“我已经完成”)并接收1字符串和2整数的响应。

How to pass the data obtained from the PHP page on the server's local page in JS? 如何在JS的服务器本地页面上传递从PHP页面获得的数据?

In order to pass data from PHP to Javascript, you must use something like an AJAX call to the PHP file. 为了将数据从PHP传递到Javascript,必须对PHP文件使用类似AJAX的调用 The response will then be whatever the PHP returns, and you can handle it with Javascript. 然后,响应将是PHP返回的结果,您可以使用Javascript处理它。

AJAX is what you need to use to establish communication between PHP and JS. 您需要使用AJAX在PHP和JS之间建立通信。 To make this simple, take a look to the Jquery AJAX documentation. 为了简化此过程,请查看Jquery AJAX文档。 If you want PHP to return your response serialized, then you'll need to use json_encode( ) 如果您想让PHP返回序列化的响应,则需要使用json_encode()

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

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