0

ユーザーにメッセージを送信するためのプラグインを作成していますが、プラグインで 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>

下手な英語でごめんなさい:)

4

1 に答える 1