我正在制作一个向用户发送消息的插件 我在插件中使用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>
抱歉英语不好:)
答案 0 :(得分:0)
WordPress希望您的JS处于noconflict模式,将代码包装如下:
jQuery( document ).ready(function( $ ) {
// Code that uses jQuery's $ can follow here.
});