Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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
Jquery 使用ajax时的样式设置问题_Jquery_Ajax - Fatal编程技术网

Jquery 使用ajax时的样式设置问题

Jquery 使用ajax时的样式设置问题,jquery,ajax,Jquery,Ajax,我正在使用JQuery和AJAX提交和处理来自。当用户单击like按钮时,信息通过AJAX发送到我的like.php文件。php文件处理请求,并为“不同”按钮创建html。“我的成功”函数将html用作“相似”按钮,并将“相似”按钮替换为新的“不相似”按钮。除此之外,当我用AJAX和JQuery替换like按钮时,like按钮的结构就消失了。我可能做错了什么 JQuery和AJAX: $(document).ready(function() { $(".like-form").submi

我正在使用JQuery和AJAX提交和处理来自。当用户单击like按钮时,信息通过AJAX发送到我的like.php文件。php文件处理请求,并为“不同”按钮创建html。“我的成功”函数将html用作“相似”按钮,并将“相似”按钮替换为新的“不相似”按钮。除此之外,当我用AJAX和JQuery替换like按钮时,like按钮的结构就消失了。我可能做错了什么

JQuery和AJAX:

$(document).ready(function() {
    $(".like-form").submit(function() {

        var dataString = $(this).serialize();
        var $this = $(this);
        $.ajax({  
            type: "POST",  
            url: "like.php",  
            data: dataString,
            success: function(html) {
                $this.replaceWith(html);
            }
        }); 

        return false; 

    });
});
原件:

<form class="like-form" method="post" action="">
    <div class="post-button">
        <button type="submit" type="submit" name="like"  
        class="like-button"/><p> Like </p></button>
    </div>
</form>

Like.php:

// Code to process the form

//This replaces the original form on submit
<form class="like-form" method="post" action="">
    <div class="post-button">
        <button type="submit" type="submit" name="unlike"  
        class="like-button"/><p> Unlike </p></button>
    </div>
</form>
//处理表单的代码
//这将替换提交时的原始表单
不像


可能这在“相似”和“不相似”中都不是合适的HTML:

<form class="like-form" method="post" action="">
    <div class="post-button">
        <button type="submit" name="Unlike" class="like-button"/>
<!-- two "type="
          closed with /> and an additional </button> at the end
-->
    </div>
</form>


尝试使用
$this.html(html)更改内容

尝试在添加“不同”按钮后增强标记-
$(document).ajaxComplete(函数(){Try{FB.XFBML.parse();}catch(ex){})你所说的“…不一样按钮的结构消失了…”是什么意思-你的意思是没有放入表单?它失去了styling@Ross-这是XFBML还是纯定制HTML?是否使用
按钮
元素上的
[name=“like”]
属性进行样式设置?