Jquery Ajax post请求没有';不能在wp主题目录中工作

Jquery Ajax post请求没有';不能在wp主题目录中工作,jquery,ajax,wordpress,http-post,Jquery,Ajax,Wordpress,Http Post,这是ajax post请求的一个示例。当放置在wordpress活动主题目录之外时,它可以工作。然而,当它在那里并且norefresh.php也上传到那里时,无论我使用的是norefresh.php的确切补丁(site/themefolder/norefresh.php或服务器补丁或本地补丁norefresh.php或/norefresh.php),它都无法工作。根本不起作用 wordpress有没有阻止执行的地方?我该怎么办 $.ajax({ 类型:“POST”, url:“norefres

这是ajax post请求的一个示例。当放置在wordpress活动主题目录之外时,它可以工作。然而,当它在那里并且norefresh.php也上传到那里时,无论我使用的是norefresh.php的确切补丁(site/themefolder/norefresh.php或服务器补丁或本地补丁norefresh.php或/norefresh.php),它都无法工作。根本不起作用

wordpress有没有阻止执行的地方?我该怎么办

$.ajax({
类型:“POST”,
url:“norefresh.php”,
数据:reqdata,
cache:false,
成功:函数(html){
//document.getElementById('myTextarea')。value=html;
警报(html);
}
});

您可以允许使用htaccess访问特定文件,但这会让您的客户感到痛苦/如果您移动站点等

最好只是从插件或主题中钩住函数。那么您就不需要担心相对URI了。(js中存在一些细微差异,但除此之外几乎相同)

add_action( 'wp_ajax_custom_hook', 'custom_function' );
add_action( 'wp_ajax_nopriv_custom_hook', 'custom_function' ); //-->front end hook...

function custom_function(){

    // handle code...
}

add_action('wp_head','define_ajaxurl'); //--> define ajaxurl using php so we can neatly place all js in js file

function define_ajaxurl() {
    ?>
    <script type="text/javascript">
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
    </script>
    <?php
}
$.ajax({
    type: "POST",
    url: ajaxurl, //-->see php function hooked to wphead to define this!!
    //data: reqdata, //--> need also to pass the action....which is the hook!! 
    data: {
        action: 'custom_hook', //-->name of hook used as above..ie. wp_ajax_nameofhook...
        'otherfield': 'yea'
    }

    cache: false,
    success: function(html) {
    //document.getElementById('myTextarea').value = html;
    alert(html);
    }
});