PDO::FETCH_ASSOC 到 Jquery
我需要从关联数组(PDO::FETCH_ASSOC)中获取数据 并将其放入下面的 3 个空文本字段中。 谁能帮我一些代码。 提前致谢。
尝试了下面的例子,没有运气:
$("#input-full-name").val(sport.values.full_name);
$("#input-short-name").val(sport.values.short_name);
$("#input-abb-name").val(sport.values.abbreviation);
I need to fetch data from an associative array (PDO::FETCH_ASSOC)
and put it in 3 empty textfields below.
Can anyone help me with some code.
Thanks in advance.
Tried the example below, no luck:
$("#input-full-name").val(sport.values.full_name);
$("#input-short-name").val(sport.values.short_name);
$("#input-abb-name").val(sport.values.abbreviation);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎混淆了服务器端和客户端操作。
PDO在服务器端运行并与数据库服务器通信。
JavaScript(在本例中为 jQuery)在客户端运行并在 DOM 上运行。
AJAX 是这两者之间的一种联系。
因此,如果您想使用数据库中的某些值填充输入字段,您可以在服务器端执行此操作:
或者您可以在客户端执行此操作(例如,如果用户单击链接/按钮/其他内容):
这是为用户提供的页面:
这是一个非常基本的示例,但我希望您能理解。另请注意,给定的 AJAX 示例仅在数组的键与输入字段的
id
属性以某种方式匹配时才有效,例如:$sport['full-name']和
。这使得使用它变得更加容易。It seems like you're confusing server-side and client-side actions.
PDO runs on the server side and communicates with the database-server.
JavaScript (in this case jQuery) runs on the client side and operates on the DOM.
AJAX is kind of a connection between those two.
So if you want to populate input-fields with some values from the database, you can either do it on the server side:
Or you can do it on the client-side (e.g. if the user clicks a link/button/whatever):
This is the page served to the user:
It's a very basic example, but I hope you get the idea. Also note that the given AJAX example only works if the keys of the array match the
id
-attributes of the input-fields in some kind, e.g.:$sport['full-name'] and <input id="input-full-name" />
. This makes it much easier to work with it.