douyong4842 2013-09-15 12:35
浏览 25

在DIV中显示回声

I'm having a very annoying issue and I have no idea what I'm doing wrong. It has (again) something to do with loading in a page into a DIV.

I have made a form which can be used to update information into a database. This form and PHP code is in one file and is being loaded in one DIV. When I visit the page which is loaded into the DIV itself, everything is working fine and the database is being updated as it should.

Though, when the page is loaded into the page. When I press submit nothing happens. What I want to happen is that the echo, which is either "Success!" or "Error!" is being displayed in the same DIV as the page is loaded into. This is my code, I hope someone can help! some variables are in Dutch, excuse me for that.

 if(isset($_POST['submit']))  {

                     include "database.php";
                     session_start();

                     $id = $_POST['id'];
                     $titel = $_POST['titel'];
                     $text = $_POST['text'];
                     $categorie = $_POST['categorie'];
                     $auteur = $_SESSION['sess_loginnaam'];
                     $laatst_aangepast = date("Y-m-d H:i:s");

                     $sql="UPDATE paginas SET id='$id', titel='$titel', text='$text', categorie='$categorie', auteur='$auteur', laatst_aangepast='$laatst_aangepast' WHERE id='$id'";
                     $result=mysql_query($sql);
                     if($result){
                     echo "Success!";
                     ?>
                     <META HTTP-EQUIV="refresh" content="2;URL=index.php">
                      <?php }
                     else {
                         echo "Mislukt!";
                     }
                 }

                 else {

                     include "database.php";
                     $id = $_GET['id'];
                     $sql="SELECT * FROM paginas WHERE id='$id'";
                     $result=mysql_query($sql);
                     $rows=mysql_fetch_array($result);

                     <form name="form1" method="post" action="">
                     ID:
                     <input name="id" type="text" id="id" value="<? echo $rows['ID']; ?>"     size="2"></div> Titel:
                     <input name="titel" type="text" id="titel" value="<? echo $rows['titel']; ?>" size="50%"> Categorie: <select name="categorie"><option    value="Paginas">Pagina's</option>
                     </select>
                     Tekst:
                     <textarea name="text" type="text" id="text" rows="31" cols="79"><?                echo $rows['text']; ? ></textarea>
                     <button type="submit" name="submit">Edit!</button>
                     </form>

And here is the code I use to load this page into the DIV:

$("#edit").on('click',function(){
$('#content').load($(this).attr('href'));
  });

So how can I manage to display the echo into the same DIV? :)

  • 写回答

1条回答 默认 最新

  • dongma6326 2013-09-15 12:41
    关注

    $.load is equivalent to $.get whereas your php code detect $_POST, that's way there is no response.

    You can change your js code to

    $("#edit").on('click',function(){
        $.post($(this).attr('href'), YOUR_FORM_DATA_HERE, function(data){
            //update your page here with response
        });
    });
    

    See $.load - jQuery Doc

    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行