仅更新页面的一部分 [英] Only update part of page

查看:121
本文介绍了仅更新页面的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近创建了一个网站,允许用户上传图片,然后让网站速度1-10图像的用户和其他用户。一切正常。当用户得分的图像,这是保存,然后另一随机框生成并presented给用户。这通过添加新的盒ID(随机生成),以查询字符串。这允许导航回到他们刚刚看到的图像的用户。

I have recently created a website that allows users to upload images and then let that user and other users of the website rate the images from 1-10. Everything is working correctly. When the user rates an image this is saved and then another random box is generated and presented to the user. This works by adding the new box id (randomly generated) to the query string. This allows for the user to navigate back to the images that they have just seen.

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

My problem comes with updating the page. Currently my code processes the rating and saves it within the database then redirects the user to the same page where I have some code to find a random image id from the database and then using that id redirects them again to the same page with the id in the querystring. This works fine however i would like to make it so that only the image and the images information (image name rating etc..) are updated and the rest of the HTML (Header, Navigation, Side bars, Footer, etc...) is not.

这是我的理解,你可以上传使用JQuery /的javascrip / AJAX网站的一部分?然而,这不会让用户重定向到previously查看的图像?

From my understanding you can upload part of a website using JQuery/Javascrip/AJAX? However this would not allow the user to redirect back to the previously viewed image?

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

If you would like any more information please ask.

修改

我已经花了一些船上的信息,并改变了我的code使用哈希值我的code是如下:

I have took some of the information on board and have altered my code to use hash values my code is below:

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我的图片之一。这code工作正常显示图像和保存图像的ID在允许我preserve图像的用户历史的URL的哈希值。但是我不确定,我怎么会找回previous散列值并重新加载图像正确的ID,当用户单击后退按钮。任何想法?

The php file testimagelook.php connects to the database and brings back a random id of one of my images. This code works fine for showing the image and saving the id of the image in the hash of the URL allowing me to preserve the users history of images. However I am unsure on how I would retrieve the previous hash value and reload the image with the correct id when the user clicks the back button. Any ideas?

推荐答案

是的,你可以做到这一点使用jQuery AJAX方法
对于你的纯朴使用

Yes you can achieve this using jQuery AJAX method
For your simplicity use this

$.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
  }
});

这篇关于仅更新页面的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆