【发布时间】:2021-06-04 20:48:24
【问题描述】:
我通常使用 javascript ajax,一切正常,但 wordpress 需要我不熟悉的 jquery ajax。
为什么下面代码中描述的变量没有定义?
var option = "'USER_ID': 'my id is 32',"
var note = "'this is my first note'";
jQuery(document).ready(function($) {
var data = {
'action': 'my_action',
option //this does not work. <--- WHAT DO YOU MEAN DOES NOT WORK?
'USER_NOTE': note //this does not work. <--- WHAT DO YOU MEAN DOES NOT WORK?
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
jQuery.post(ajaxurl, data, function(response) {
alert('Got this from the server: ' + response);
});
});
【问题讨论】:
-
您好,您可以显示
divsnamehtml 吗? -
var divsname = document.getElementById("userid");
-
divsname是 id 吗?那么为什么需要使用 forEach 呢? -
那部分不重要,随便放,问题是我不能在data ajax里面放任何变量来发送
-
var divsname = document.getElementById("userid").getAttribute("class");
标签: jquery ajax variables foreach send