我编写了一个 Wordpress 插件,它在后期编辑页面的元框中放置了几个按钮。我会去example.com/wp-admin/post.php?post=number1&action=edit。我希望我的 Wordpress 挂钩接收 AJAX 调用,然后向远程服务器发出请求(需要 WP 用户不必输入的身份验证),然后将结果返回给 Wordpress 用户。
我要发送的带有数据的表单代码是两个自定义 HTML 元素的输入数据。他们是:
class MyFormData extends HTMLElement{
constructor() {
super();
}
connectedCallback(){
const li = document.createElement('li');
const newDat = document.createElement('input');
newDat.setAttribute('type','text');
newDat.setAttribute('name',`title box`);
newDat.setAttribute('placeholder',`Test Data`);
const deleteButton = document.createElement('button');
deleteButton.setAttribute('type','button');
deleteButton.innerHTML = "-";
deleteButton.addEventListener("click",function(){
li.parentNode.remove();
});
li.appendChild(newDat);
li.appendChild(deleteButton);
this.appendChild(li);
}
}
customElements.define('form-data',MyFormData);
Run Code Online (Sandbox Code Playgroud)
和
class DurationMenu extends HTMLElement{
constructor(){
super();
}
connectedCallback(){
const amount = document.createElement('input');
amount.setAttribute('id','selectedTime');
amount.setAttribute('type','number');
amount.setAttribute('step',5)
amount.setAttribute('name','duration');
amount.setAttribute('min',5);
amount.setAttribute('max',60);
amount.setAttribute('value',15);
this.appendChild(amount)
}
}
customElements.define('duration-choice', DurationMenu);
Run Code Online (Sandbox Code Playgroud)
这两个自定义元素都显示在元框中。我有一个用于提交按钮的自定义元素:
import …Run Code Online (Sandbox Code Playgroud) 我正在尝试用 Vanilla JS 编写这个 jQuery ajax POST 请求;它最初是:
$.ajax({
method: 'POST',
url: window.location.href + 'email',
data: {
toEmail: to, //var set elsewhere
fromName: from, //var set elsewhere
message: message, //var set elsewhere
recaptcha: recaptcha //var set elsewhere
}
})
.done(function (data) {
handleResponse(data, form)
})
.fail(function (error) {
console.error(error)
alert('Couldn't send your email. Try again later.')
})
Run Code Online (Sandbox Code Playgroud)
处理响应是
function handleResponse (data, form) {
if (!data.message) return
if (!form) return
const responseMessage = form.querySelector('[email-response]')
const formData = form.querySelector('[email-data]')
if ('success' === …Run Code Online (Sandbox Code Playgroud) 所以我知道在C中,'\ 0'是空字符,用于终止字符串.我一直在寻找网上看到其实际作用,而且我已经运行有没有它在我的琴弦看到它的用途和区别不使用的程序.我找不到任何东西.
当我的琴弦缺少'\ 0'字符时,我该怎么办?
没有\ 0的代码对我有用:
char a[10] = {'a','b','c','d','e','f','g'};
int x = strlen(a);
char b[10] = {'h','i','j','k','l'};
int y = strcmp(a,b);
printf("%d\n",x);
printf("%d\n",y);
Run Code Online (Sandbox Code Playgroud)