首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Ajax加载CF7表单

通过Ajax加载CF7表单
EN

Stack Overflow用户
提问于 2013-05-12 01:50:38
回答 2查看 2.7K关注 0票数 0

我会通过ajax加载页面的内容,里面有我的一个表单通过CF7插件生成的短码。当呈现内容时,不会处理短码并将其打印为文本。有没有办法在ajax调用中强制执行短代码?谢谢你M。

这是js脚本:

代码语言:javascript
复制
function getcontent(postid){
    // here is where the request will happen
    jQuery.ajax({
        url: '/wp-admin/admin-ajax.php',//ajax controller request
        data:{
            'action':'dch',//action invoked
            'fn':'ghcontent',//function required
            'postid':postid//if of post required
        },
        cache: false,
        async:true,
        timeout: 3000,
        success:function(data){
            jQuery("#posthome").html(data);//print the html (content)
        },
        error: function(errorThrown){
            console.log(errorThrown);
        }
    });
}

这是我的php代码:

代码语言:javascript
复制
add_action('wp_ajax_nopriv_dch', 'ghcontent');
add_action('wp_ajax_dch', 'ghcontent');
function ghcontent(){
  $args = array('page_id' => $_REQUEST['postid']);
  query_posts($args);
  if(have_posts()) : 
    while (have_posts()) : the_post();
      the_content();
    endwhile;
  endif;
  die();
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-01-13 01:30:21

do_shortcode在您的admin-ajax.php中不起作用,请尝试生成您自己的ajax操作。检查类似问题的以下答案:https://wordpress.stackexchange.com/questions/53309/why-might-a-plugins-do-shortcode-not-work-in-an-ajax-request

票数 0
EN

Stack Overflow用户

发布于 2013-05-12 02:02:59

the_content筛选器运行时,将应用快捷代码:

代码语言:javascript
复制
$post = get_post( $_REQUEST['postid'] );
$return = apply_filters( 'the_content', $post->post_content );
echo $return;
die();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16500088

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档