$ _GET updated_value(?) - 另一个就地编辑器(Jquery插件)问题

时间:2009-03-27 05:03:41

标签: php jquery mysql

使用PHP和MySql,我试图在这里实现这个相当时髦的就地编辑器:

教程: http://www.davehauenstein.com/code/jquery-edit-in-place/

js文件: http://davehauenstein.com/code/scripts/jquery.inplace.min.js

好的,发生了什么,

  1. 我点击元素编辑文字。
  2. 我清除旧文本,然后输入新文本。
  3. 我在元素外部单击以启动Ajax以保存新文本。
    1. Ajax显示“Saving ..”,这是更新元素的默认文本。
    2. 新文本在数据库中更新。
  4. 元素重新加载,而不是在元素内显示新文本,元素显示(单击此处编辑文本),这是js文件中返回空元素的默认文本。
  5. 问题:只有在我手动刷新页面后,才会在元素中加载新文本。而不是在没有刷新的情况下加载元素。

    具有就地编辑的元素:

    <div class="editme1"><?php
    $content = $_GET['update_value'];
    // i added this to try and get the updated value but im
    // not really sure, just a guess. i have also used $_POST
    // in an attempt to catch it....but i feel stupid even
    // saying that..lol
    if(!empty($content)) { echo "$content"; } else 
    { echo "$row[profilevalue_8]"; }
    ?></div>
    

    更新数据库的文件(update.php):

    <?php include('includes/config.php');
    include('includes/functions.php');
    $name = $_POST[update_value];
    $update = mysql_query("UPDATE profilevalues SET profilevalue_8 = '".$name."' 
    WHERE profilevalue_user_id = '".uid()."'") or die(mysql_error());
    ?>
    

    javascript

    <script type="text/javascript">
        $(document).ready(function(){
            $(".editme1").editInPlace({
                url: "http://www.mysite.com/update.php",
                params: "ajax=yes",
            });
    </script>
    

    我想问题是,我似乎无法按预期反映元素的变化。

    如果有任何帮助,我将非常感激。

    由于

2 个答案:

答案 0 :(得分:1)

你忘记了update.php :)中的每一个In in Place编辑器对更新文件发出了一个AJAX请求,然后在编辑后的元素中添加了update.php中带有该请求的内容。< / p>

所以你的update.php需要像这样

<?php include('includes/config.php');
include('includes/functions.php');
$name = $_POST[update_value];
$update = mysql_query("UPDATE profilevalues SET profilevalue_8 = '".$name."' 
WHERE profilevalue_user_id = '".uid()."'") or die(mysql_error());

echo $_POST['update_value']; //add this to your file and it should be working now
?>

答案 1 :(得分:0)

为了补充Bogdan Constantinescu所说的内容,我认为值得指出的是,为了防止人们输入令人讨厌的数据,你应该真的

  • 在您以HTML格式发送到浏览器的任何不受信任的字符串上调用htmlspecialchars()。这有助于防止XSS攻击。
  • 对您直接放入SQL语句的任何字符串调用mysql_real_escape_string()。这将保护您免受SQL注入攻击。
相关问题