weixin_33713707 2020-03-07 17:21 采纳率: 0%
浏览 24

AJAX堆栈来自PHP的响应

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/13822322/jquery-how-to-clear-an-element-before-appending-new-content" dir="ltr">Jquery: How to clear an element before appending new content?</a>
                            <span class="question-originals-answer-count">
                                (4 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2020-03-07 17:36:39Z" class="relativetime">last month</span>.</div>
        </div>
    </aside>

I've recently started using and learning JS and jquery. I'm sending a user email from a form to my PHP page to check if any user exists in DB via ajax, then I get a response from my PHP file if the user exists or not and display the text in a div. It's working fine, but because the page doesn't refresh when the button for sending form data is pressed, ajax just stacks the response from PHP.

I probably need to clear the response every time the button is clicked first and then append the response but I can't find the right command for it :/

JS

function sendnewpass() {
        var email = document.getElementById("useremail").value;

        $.ajax({
            type : "POST",
            url  : "login.php", //my php page
            data : { passemail : email },  //passing the email
            success: function(res){  //to do if successful
                $("#emailsentmsg").append(res);  //the the div that i put the response in
            }
        });

}
</div>
  • 写回答

2条回答 默认 最新

  • weixin_33713503 2020-03-07 17:24
    关注

    Use the following:

    $("#emailsentmsg").html("");
    $("#emailsentmsg").append(res);
    

    Or shorter (thanks @Ivar):

    $("#emailsentmsg").html(res);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料