2014-09-23 75 views
0

我有一个论坛,允许用户编辑和删除他的评论,我已经定义了一个“编辑”按钮,通过点击鼠标可以打开一个模式,并在该模式用户被允许访问他/她以前发送的数据,我写了一个ajax来定位这些字段,并在用户点击“编辑”按钮时更新它们,代码完全有意义,但到目前为止该功能不会使用户点击,模式下降,他/她发布的任何内容都会显示在字段中,并且模式底部会出现一个“编辑”按钮,该按钮负责更改并更新数据。这里是模态代码:Ajax没有更新数据

   <button id="btn-btnedit" class="btn btn-primary " data-toggle="modal" data-target="#myModal<?php echo $list['id']; ?>"> 
        Edit <i class="fa fa-pencil-square-o"></i> 
       </button> 


       <!-- Modal --> 
       <div class="modal fade" id="myModal<?php echo $list['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
        <div class="modal-dialog"> 
        <div class="modal-content"> 
         <div class="modal-header"> 
         <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> 
         <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
         </div> 
         <div class="modal-body"> 
         <div class="container"> 
            <form style="width: 550px;" action="" method="post" id="signin-form<?php echo $list['id']; ?>" role="form"> 
            <input type="hidden" name="commentID" value="<?php echo $list['id']; ?>"> 
            <div class="from-group"> 

             <label for="title">Title: </label> 
             <input class="form-control" type="text" name="title" id="txttitle" value="<?php echo $list['title']; ?>" placeholder="Page Title"> 

            </div> 
            <div class="from-group"> 

             <label for="label">Label: </label> 
             <input class="form-control" type="text" name="label" id="txtlabel" value="<?php echo $list['label']; ?>" placeholder="Page Label"> 

            </div> 

            <br> 

            <div class="from-group"> 

             <label for="body">Body: </label> 
             <textarea class="form-control editor" name="body" id="txtbody" row="8" placeholder="Page Body"><?php echo $list['body']; ?></textarea> 

            </div> 
            <br> 
            <input type="hidden" name="editted" value="1"> 
            <br> 
            <br> 
            <input type="submit" id="btnupdate" value="Edit"> 
           </form> 
         </div> 
         </div> 

,你可以看到我已经指派“editted”我的“name”属性,这就是后来的上用于调用数据库中的查询,SQL代码如下:

 case 'postupdate'; 

     if(isset($_GET['editted'])){ 

       $title = $_GET['title']; 
       $label = $_GET['label']; 
       $body = $_GET['body']; 

        $action = 'Updated'; 
        $q = "UPDATE posts SET title ='".$title."', label = '".$label."', body = '".$body."' WHERE id = ".$_GET['commentID']; 
        $r = mysqli_query($dbc, $q); 


        $message = '<p class="alert alert-success"> Your Post Is Succesfully '.$action.'</p>' ; 


      } 

这里是ajax代码片段;

$('#btnupdate').click(function() { 
    var tempTitle = $('#txttitle').val(); 
    var tempLabel = $('#txtlabel').val(); 
    var tempBody = $('#txtbody').val(); 
    var tempUrl = "index.php?page=postupdate"+"&title="+tempTitle+"&label="+tempLabel+"&body="+tempBody+"&commentID=30&editted=1"; 
    $.get(tempUrl); 
}); 

我假设有关于这个部分的代码没有什么进步,我失去了一些东西很简单,任何代价的高度赞赏:)

+0

你应该做一个帖子,而不是一个get。内容可能会很长。 (大小写注入) – Daan 2014-09-23 14:20:22

+0

你好大安,在发布之前尝试过,好吧,这比我想的方法还要多 – 2014-09-23 14:23:00

+0

你对.get()的结果不做任何事情,你没有通过回调... – FrancescoMM 2014-09-23 14:23:16

回答

0

这(未经测试的代码)可以是类似于您应该做的:

$('#btnupdate').click(function() { 
    var tempTitle = $('#txttitle').val(); 
    var tempLabel = $('#txtlabel').val(); 
    var tempBody = $('#txtbody').val(); 
    var tempParams = {"page":"postupdate","title":tempTitle,"label":tempLabel,"body":tempBody,"commentID":30,"editted":1}; 

    $.post("index.php",tempParams,function(data) { 
     alert(data); 
    }); 
}); 

UPDATE

尝试AJAX,而不是能看到,如果一些错误发生S IN装载

$.ajax({url:"index.php",data:tempParams,type: "POST"}).done(function() { 
    alert("success"); 
}).fail(function() { 
    alert("error"); 
}).always(function() { 
    alert("complete"); 
});` 

UPDATE

开始测试,如果单击处理工作,然后(只是可以肯定的!)。

$( '#btnupdate')点击(函数( ){alert(“是的,至少按下了按钮”); });如果脚本被执行,然后

UPDATE

开始测试:

alert("yes at least the script gets executed"); 
$('#btnupdate').click(function() { alert("yes at least the button was pressed"); }); 

如果没有,你必须有一个JavaScript错误的地方。 https://webmasters.stackexchange.com/questions/8525/how-to-open-the-javascript-console-in-different-browsers

如果是的话,你的按钮没有得到的jQuery捕获(不知道为什么)

反正它什么都没有做与AJAX或搞定!

+0

没有结果的人... – 2014-09-23 14:34:34

+0

@EscapeCharacter没有javascript错误,没有加载,没有任何操作? – FrancescoMM 2014-09-23 14:37:48

+0

有一个加载,我不知道什么,但没有错误,迄今为止没有行动.....我试图通过它的工作原理手动更新数据,但不知何故在这段代码中,是缺少,我非常寻找它.... – 2014-09-23 14:39:59