gpt4 book ai didi

php - 只更新部分页面

转载 作者:行者123 更新时间:2023-11-30 10:34:32 25 4
gpt4 key购买 nike

我最近创建了一个网站,允许用户上传图片,然后让该用户和该网站的其他用户对图片进行 1 到 10 的评分。一切正常。当用户对图像进行评分时,这将被保存,然后生成另一个随机框并呈现给用户。这通过将新的框 ID(随机生成)添加到查询字符串来实现。这允许用户导航回他们刚刚看到的图像。

我的问题来自更新页面。目前我的代码处理评级并将其保存在数据库中,然后将用户重定向到同一页面,我有一些代码从数据库中找到随机图像 ID,然后使用该 ID 将他们再次重定向到同一页面,其中的 ID 为查询字符串。这工作正常,但我想这样做,以便只更新图像和图像信息(图像名称评级等),其余的 HTML(页眉、导航、侧边栏、页脚等...)不是。

据我了解,您可以使用 JQuery/Javascrip/AJAX 上传网站的一部分吗?但是,这不允许用户重定向回之前查看过的图像吗?

如果您想了解更多信息,请询问。

编辑

我已经获取了一些信息并更改了我的代码以使用哈希值我的代码如下:

HTML

<img id="design" alt="" width="300" height="300"  />
<input type="button" id="GetImage" value="Get Image" />

JQUERY

$(document).ready(function(){

$("#GetImage").click(function() {

$.ajax({ //Make the Ajax Request
type: "POST",
url: "testimagelook.php", //file name
success: function(server_response){
var id = server_response;
document.location.hash = id;
$('#design').attr('src','img/boxes/'+id+'.png');
}
});
});

});

php 文件 testimagelook.php 连接到数据库并返回我的其中一张图像的随机 ID。此代码可以很好地显示图像并将图像的 ID 保存在 URL 的哈希值中,从而允许我保留图像的用户历史记录。但是,我不确定如何在用户单击后退按钮时检索以前的哈希值并使用正确的 ID 重新加载图像。有什么想法吗?

最佳答案

是的,您可以使用 jQuery AJAX 方法实现此目的
为简单起见,请使用此

$.post('pageURL.php', {data1: value1}, function(result) {
// Update the portion of the page you wish to

});

已更新

$.ajax({
type: "POST",
url: "PageName.aspx/MethodName",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
// Now receive the data (information) in the form of JSON
// In this JSON you can pass the imageID or anything to proceed your logic
// and update the portion of the page you wish to
}
});

关于php - 只更新部分页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14832144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com