我正在制作一个用于向用户发送消息的插件,我在插件中使用了 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>
抱歉英语不好:)