Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax用另一个div替换div(新css)_Javascript_Jquery_Html_Css_Ajax - Fatal编程技术网

Javascript Ajax用另一个div替换div(新css)

Javascript Ajax用另一个div替换div(新css),javascript,jquery,html,css,ajax,Javascript,Jquery,Html,Css,Ajax,我在模板上有一个按钮和用户名,如果用户单击按钮,Ajax应该用一些使用新CSS样式的消息替换用户名和按钮 这是我的Ajax: $('#fulfillButton').bind('click',function() { $.ajax({ type : "GET", contentType : "application/json; charset=utf-8", url : "order/${orderID}", dateTyp

我在模板上有一个按钮和用户名,如果用户单击按钮,Ajax应该用一些使用新CSS样式的消息替换用户名和按钮

这是我的Ajax:

$('#fulfillButton').bind('click',function() {
    $.ajax({
        type : "GET",
        contentType : "application/json; charset=utf-8",
        url : "order/${orderID}",
        dateType : "json",
        cache: false,
        success: function (data) {
            if(data.statusCode=="OK")
            {
                $('#replace').replaceWith("<div class ="error_message">"+ data.body +"</div>");
            }
        },

        error: function (data) {
            alert("Something went wrong, please retry again");
        },
   });
});
$('fulfillButton').bind('click',function(){
$.ajax({
键入:“获取”,
contentType:“应用程序/json;字符集=utf-8”,
url:“订单/${orderID}”,
日期类型:“json”,
cache:false,
成功:功能(数据){
if(data.statusCode==“OK”)
{
$('#replace').replacetwith(“+data.body+”);
}
},
错误:函数(数据){
警报(“出现问题,请重试”);
},
});
});
这是我的html:

<div id="replace">
    <div class="full_name">
        ${name}
    </div>
    <button id="fulfillButton" type="button" class="action-button shadow animate green">
        FulFill
    </button>
</div>
<button id="goBackButton" type="button" class="go_back_button">
    Go Back
</button>

${name}
完成
回去

然而,当我点击按钮时,什么也没发生。我错过了什么?我使用的是jQuery1.6。

您的代码总体上很好,并且可以正常工作。唯一出错的是replace元素的html转义:

// before
$('#replace').replaceWith("<div class ="error_message">"+ data.body +"</div>");

// after
$('#replace').replaceWith('<div class="error_message">' + data.body + '</div>');
//之前
$('#replace').replacetwith(“+data.body+”);
//之后
$('#replace').replacetwith(''+data.body+'');
您应该真正更新jQuery版本<代码>1.6已经有一百年的历史了!:)


调试器中有错误吗?@JaxTeller如果我删除“”“tag,它工作得很好。所以问题是我可能没有正确使用div标记。因此,请参阅我的答案,@user3369592;)我同意你的看法……但我们的框架仍在使用1.6……我自己无法更新……这取决于你。;)但它甚至可以与
1.6
一起使用,我已经测试过了@用户3369592