使用 AJAX 通过每次点击更新信息
好的,我有一个表格,一旦单击就会更改显示的文本,就像 http://www 上显示的文本一样.w3schools.com/ajax/ajax_database.asp
我试图根据每次点击来更新它。 例如。
Page Load > Load news article 1
onClick 1 > Load news article 2
onClick 2 > Load news article 3
我想要的只是让它根据每次点击更改为后续值。我有一个 php mysql 数据库脚本,每次调用时都会从数据库中提取数据。
真正的问题是:我应该对 php 进行编程以返回带有新数据的新表格数据单元格
oncLick="showNews($next_number)"
,还是应该将其留给 AJAX,在它请求信息之前,只需将其 +1 即可。
我是 AJAX 编程新手,对 PHP 没有那么丰富的经验。我到处搜索过,如果这是一个多余的问题,我深表歉意。只要给我指出正确的方向即可。
Ok I have a table that changes the displayed text once clicked on like the one displayed on http://www.w3schools.com/ajax/ajax_database.asp
I'm trying to update it based on each click.
For example.
Page Load > Load news article 1
onClick 1 > Load news article 2
onClick 2 > Load news article 3
All I want is for it to change based on each click, to a subsequent value. I have a php mysql database script that will pull the data from the database each time called.
The real question: Should I program the php to return a new table data cell with the new
oncLick="showNews($next_number)"
or should I leave that up to the AJAX, before it requests the information, just +1 it up.
I'm new to AJAX programming and not that experienced in PHP. I have searched everywhere and apologize if this is a redundant question. Just point me in the right direction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
写一个php函数支持通过id获取内容。
showNews(新闻 ID)
。然后通过ajax请求传递newid。无需更改 PHP 中的 newsid。write a php function to support to get the content by id.
showNews(news ID)
. and then pass the newid with the ajax request. no need to change the newsid in the PHP.我猜这样的事情是最简单的:
说实话,只要选择对你来说更自然的方式即可。除非这只是大事的一小部分,否则没关系。
I'm guessing something like this would be simplest:
To be honest, just pick the way which seems more natural to you. Unless this is only a small part of something huge, it won't matter.
如果我理解正确的话,你想在单击按钮时获取下一条新闻...
我建议你使用 jQuery 进行 Ajax 请求...
它可能是这样的:
在 PHP 中:
if I understood right, you want to get the next news when clicking on your button...
I suggest you to use jQuery for Ajax request...
It could be like this:
And in PHP: