简体   繁体   English

使用PHP从数据库中提取值并将结果作为变量传递给JavaScript

[英]Use PHP to extract values from database and pass the results as a variable to JavaScript

I have a JS/Html file and a PHP script. 我有一个JS / Html文件和一个PHP脚本。 The PHP file creates a database connection and returns the result of the DB query. PHP文件创建数据库连接并返回数据库查询的结果。

The html page uses an ajax request to get the data and echos it back to the html page - but it is returned as text (xmlhttp.responseText), which I can display, but can't easily manipulate. html页面使用ajax请求来获取数据并将其回送到html页面 - 但它以文本(xmlhttp.responseText)的形式返回,我可以显示,但不能轻易操作。

I would like to return the data as an array that I can process in JavaScript. 我想将数据作为可以在JavaScript中处理的数组返回。

Is there a way for an ajax request to include the response as a variable, instead of as raw text? 有没有办法让ajax请求将响应包含为变量而不是原始文本?

If I can provide more information to make it easier to answer, let me know! 如果我能提供更多信息以便于回答,请告诉我!

thanks! 谢谢!

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

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