Ajax警告框显示HTML代码

Ajax alert box is showing HTML code

本文关键字:HTML 代码 显示 警告 Ajax      更新时间:2023-09-26

我使用jQuery AJAX在动态按钮单击上调用参数化函数。脚本和功能工作正常。唯一的问题是,它显示所有的HTML代码到警告框。从。我不需要显示HTML代码,只需要显示成功的消息。谁来帮帮我吧。由于

<html>
    tables, textbox, buttons
</html>
<?php
//some php, sql stuff
    echo "<td><input type='button' name='disable' value='Disable' onClick='disable($id);'/></td>";
?>
<script>
    function disable(id) { 
        jQuery.ajax({   type: 'Post', 
                    url: '', 
                    data: {action: 'delete', ID: id} 
        })
        .done(function(data) { 
           alert("Data Saved: " + data); 
            location.reload();
        }); 
    }
</script>

警告框显示html块中的html代码和php块中的成功消息。我不需要显示HTML代码,只需要显示成功的消息。

我经常使用这种方案。在php

echo "response_ok";

在javascript中,我测试php是否响应ok:

$.get("checkfornew.php", function(data, status)
    {
        if ( data.indexOf("response_ok") != -1)
        {
              //response contains "response_ok" string
        }
   });

如果你想显示没有html标签的php响应,你可以从javascript中剥离html标签。但是我只是从php中显示一个"response_ok"消息,如果javascript收到这个响应,它会显示一个已经隐藏在html页面中的html。