Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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
Php Ajax中的短代码_Php_Jquery_Ajax - Fatal编程技术网

Php Ajax中的短代码

Php Ajax中的短代码,php,jquery,ajax,Php,Jquery,Ajax,因此,我有以下ajax设置: PHP:menu.PHP <!--Menu--> <div class="rh_menu"> <a href="#rhp_front_rhp_id" class="is-active" id="rhp_id">Front</a> <a href="#rhp_front_ca_other_id" id="ca_other_id">Other</a> </div>

因此,我有以下ajax设置:

PHP:menu.PHP

<!--Menu-->
<div class="rh_menu"> 
  <a href="#rhp_front_rhp_id" class="is-active" id="rhp_id">Front</a>    
  <a href="#rhp_front_ca_other_id" id="ca_other_id">Other</a>   
</div>
<!--Content Div-->
<div class="rhp_hide">
    <div class="rrp_container is-active" id="rhp_front_rhp_id">
        <div class="spinner is-active"></div>
    </div>
    <div class="rrp_container" style="display:none;" id="rhp_front_ca_other_id">
        <div class="spinner"></div>
    </div>
</div> 
// load the javascript
wp_enqueue_script( 'ajax-script', '/03.includes/js/rh_ajax.js', array('jquery') );   
wp_localize_script( 'ajax-script', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );

//Ajax call for House front page
function my_tab_callback() {  
    $template_part_path = 'page-parts/01_house_' . $_GET['id'];
    get_template_part($template_part_path);
    exit;
}
add_action('wp_ajax_my_tab', 'my_tab_callback');
add_action('wp_ajax_nopriv_my_tab', 'my_tab_callback');
rh_ajax.js

//To hide other divs
jQuery('.rh_menu a').click(function() {
    var rh_id = jQuery(this).attr('id');
    jQuery('[id^="rhp_front_"]').hide();
    jQuery('#rhp_front_' + rh_id).show();
    });
//To initiate first click
jQuery(window).load(function() { 
    jQuery("#rhp_id" ).trigger( 'click' );  
    return false;       
    });
//Ajax call     
jQuery(document).ready(function() {
    jQuery('.rh_menu a').click(function(e) {
        e.preventDefault();

        var tab_house_id = jQuery(this).attr('id'); 


        jQuery.ajax({
            type: "GET",
            url: ajax_object.ajax_url,
            dataType: 'html',
            data: ({ action: 'my_tab', id: tab_house_id}),
            success: function(data){
                  jQuery('#rhp_front_' + tab_house_id).html(data);
                  console.log(data);

        },
        error: function(data)  
        {  
        alert("Nope");
        console.log(data);
        return false;
        }  

        }); 

   }); 
 }); 
所以,当一个短代码被ajax解析时,它看起来是无法识别的,并且给了我500个服务器错误

如何修改上述设置,以便在ajax设置中使用快捷码


谢谢

url:ajax\u object.ajax\u url?网址到底是什么?嗨。谢谢你的回复。我尝试了“”的解决方案,但没有成功。我从中得到了“ajax\u object.ajax\u url”。您需要使用
wp\u localize\u script()
来定义
ajax\u object.ajax\u url
。我总是喜欢使用
wp\u enqueue\u script()
+
wp\u localize\u script()
,而不是直接在template.Hi中添加脚本。我重新编辑了上面的问题。我实现了您的解决方案,但仍然出现错误。我仍然得到500(内部服务器错误)。我做错了什么?谢谢我还将短代码改为简单的段落,看看它是否有效(以消除可能的短代码错误)。但是我得到了同样的错误。不要使用
get\u template\u part
尝试使用
ob\u get\u content
url:ajax\u object.ajax\u url?网址到底是什么?嗨。谢谢你的回复。我尝试了“”的解决方案,但没有成功。我从中得到了“ajax\u object.ajax\u url”。您需要使用
wp\u localize\u script()
来定义
ajax\u object.ajax\u url
。我总是喜欢使用
wp\u enqueue\u script()
+
wp\u localize\u script()
,而不是直接在template.Hi中添加脚本。我重新编辑了上面的问题。我实现了您的解决方案,但仍然出现错误。我仍然得到500(内部服务器错误)。我做错了什么?谢谢我还将短代码改为简单的段落,看看它是否有效(以消除可能的短代码错误)。但是我遇到了同样的错误。请尝试使用
ob\u get\u content
//To hide other divs
jQuery('.rh_menu a').click(function() {
    var rh_id = jQuery(this).attr('id');
    jQuery('[id^="rhp_front_"]').hide();
    jQuery('#rhp_front_' + rh_id).show();
    });
//To initiate first click
jQuery(window).load(function() { 
    jQuery("#rhp_id" ).trigger( 'click' );  
    return false;       
    });
//Ajax call     
jQuery(document).ready(function() {
    jQuery('.rh_menu a').click(function(e) {
        e.preventDefault();

        var tab_house_id = jQuery(this).attr('id'); 


        jQuery.ajax({
            type: "GET",
            url: ajax_object.ajax_url,
            dataType: 'html',
            data: ({ action: 'my_tab', id: tab_house_id}),
            success: function(data){
                  jQuery('#rhp_front_' + tab_house_id).html(data);
                  console.log(data);

        },
        error: function(data)  
        {  
        alert("Nope");
        console.log(data);
        return false;
        }  

        }); 

   }); 
 });