javascript - AJAX 发布后通过 jQuery 修改内容

标签 javascript jquery wordpress

我正在尝试使用 jQuery 来修改来自 AJAX 的一些内容,但由于某种原因它似乎无法访问该内容。我对 jQuery 还很陌生,所以我不确定哪里出了问题,希望这里有人能给我指出正确的方向。

所有代码都位于 GitHub 上 https://github.com/Ryan-Myers/WordPress-Survey-Plugin/blob/master/survey-js.php

但是相关代码如下(顺便说一句,这是wordpress插件的一部分):

//Add a new question to the passed survey
function add_question(survey_id) {
    var data = {
        action: 'survey_add_question_ajax',
        security: '<?php echo wp_create_nonce("survey_add_question_nonce"); ?>',
        survey: survey_id
    };

    jQuery.post(ajaxurl, data, function(response) {
        jQuery('#survey-admin-page').html(response);
        jQuery('#survey-questions-table').slideUp();
        jQuery('#survey-add-question').slideDown();
    });

    //FAILS HERE
    jQuery('#survey-add-question').ready(function(){
        //Default to hiding the question setup until they select a question type.
        jQuery('#questionsetup').hide();
        jQuery('#save_question').attr('onclick', 'submit_question('+survey_id+')');

        //Testing to see if it will return a usable value, which it doesn't.
        alert(jQuery('#save_question').attr('onclick'));
    });
}

最佳答案

$.ready 不是这样工作的: http://api.jquery.com/ready/

The .ready() method can only be called on a jQuery object matching the current document, so the selector can be omitted.

您通常使用它来了解 DOM 何时准备就绪,然后开始执行依赖于 DOM 的代码。

您可以在slideDown之后将不起作用的代码块添加到$.post的回调中,也可以向slideDown添加一个回调,该回调将在slideDown完成后触发:http://api.jquery.com/slideDown/

关于javascript - AJAX 发布后通过 jQuery 修改内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7815679/

相关文章:

css - Wordpress 样式额外边距

javascript - Angularjs - 范围的变化没有反射(reflect)出来

javascript - 从所有匹配的表单元素中删除一个类..最干净的方法?

javascript - 有什么原因滚动条=是不起作用吗?

Jquery - 选择器 - 选择 div 中的每个元素

javascript - Uncaught TypeError : app. all is not a function

php - Wordpress:将一个页面的内容包含在另一个页面中

javascript - 使用 jQuery 读取 utm 查询字符串

javascript - 在 jQuery 中选择具有命名空间的节点

Wordpress 混合内容错误(谷歌字体相关)