Php wordpress管理员ajax don';行不通

Php wordpress管理员ajax don';行不通,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我正在制作一个向用户发送消息的插件 我在插件中使用ajax 而且我没有得到正确的方法 这是我的jQuery代码 我试了很多次,但都做不成 <script type="text/javascript"> $(document).ready(function () { $(document).ajaxStop(function () { $.unblockUI(); }); //if form is submitted $('#whats

我正在制作一个向用户发送消息的插件 我在插件中使用ajax 而且我没有得到正确的方法 这是我的jQuery代码 我试了很多次,但都做不成

<script type="text/javascript">
$(document).ready(function () {
    $(document).ajaxStop(function () {
        $.unblockUI();
    });

    //if form is submitted
    $('#whatsappform').submit(function (e) {
        if ($('#whatsappform').validate().form() === false) {
            return false;
        }

        //Store original html to replace back in box later.
        var original = $('#faketextbox').html();
        //Scan html code for emojis and replace with text and special marker.
        $('#faketextbox img').each(function (index) {
            var emojiUnicode = this.outerHTML.match(/emoji-(.*?)"/)[1];
            $(this).replaceWith('##' + emojiUnicode + '##');
        });
        //Replace all BR's with line breaks.
        var message = $.trim($('#faketextbox').html().replace(/<br\s?\/?>/g, "\n"));
        //Copy the corrected message text to our hidden input field to be serialised.
        $('#message').val($('#faketextbox').html(message).text());
        //Replace the corrected text with the original html so it shows properly on a browser.
        $('#faketextbox').html(original);
        //Continue with the form.
        var formData = $("#whatsappform").serialize();

        $.ajax({
            type: "POST",
            url: "http://localhost:81/wp/wp-admin/admin-ajax.php",
            cache: false,
            data: formData,
            dataType: "json",
            timeout: 45000,
            success: onSuccess,
            error: onError,
            //beforeSend: function(jqXHR, settings) {
            //},
            complete: function () {
                $.unblockUI();
            }
        });

        return false;
    });

</script>

$(文档).ready(函数(){
$(文档).ajaxStop(函数(){
$.unbui();
});
//如果提交了表格
$('whatsappform')。提交(函数(e){
if($('#whatsappform').validate().form()==false){
返回false;
}
//将原始html存储起来,以便稍后替换回文本框中。
var original=$('#faketextbox').html();
//扫描html代码中的表情符号,并替换为文本和特殊标记。
$('#faketextbox img')。每个(函数(索引){
var emojionicode=this.outerHTML.match(/emoji-(.*)/)[1];
$(this).replacement为(“##”+emojionicode+”#);
});
//用换行符替换所有BR。
var message=$.trim($('#faketextbox').html().replace(//g,“\n”);
//将更正后的消息文本复制到隐藏的输入字段以进行序列化。
$('#message').val($('#faketextbox').html(message.text());
//将更正后的文本替换为原始html,以便在浏览器上正确显示。
$('#faketextbox').html(原件);
//继续填写表格。
var formData=$(“#whatsappform”).serialize();
$.ajax({
类型:“POST”,
url:“http://localhost:81/wp/wp-admin/admin ajax.php“,
cache:false,
数据:formData,
数据类型:“json”,
超时:45000,
成功:一旦成功,
错误:onError,
//发送前:函数(jqXHR,设置){
//},
完成:函数(){
$.unbui();
}
});
返回false;
});

很抱歉英文不好:)

WordPress希望您的JS处于模式,请按如下方式包装代码:

jQuery( document ).ready(function( $ ) {
    // Code that uses jQuery's $ can follow here.
});

请发布最少的代码来突出显示您的问题。好的,谢谢您这么做。现在请准确地提供不起作用的内容,以及您收到的任何错误消息(客户端或服务器端),等等。你提供的越多,我们就越有可能帮助你。我为成功的消息编写了一些函数,但它在成功时总是出错:(你能给我提供一个gudie,让它在同一页上正确地执行吗:)没问题,但我成功了:ajax调用成功了,但返回的数据有一个错误:HTTP状态:200StatusTextOK我该怎么办@diggy