【发布时间】:2021-06-05 11:27:18
【问题描述】:
在javascript中这很容易,wordpress需要jquery ajax,我对jquery不是最熟悉的。下面的例子可以用ajax jquery吗?
如何发送多个变量,使“var note++”增加一个数字,发送为:
note1 = "我的笔记 1",
note2 = "我的笔记 2",
note3 = "我的笔记 3",
note4 = "我的笔记 4",
还有更多.....
var i = "";
var note = "";
var divsname = document.getElementsByClassName("notes");
for (i = 1, i++) {
divsname.forEach(function(div) {
note += note i++ = div.innerHTML;
});
jQuery(document).ready(function($) {
var data = {
'action': 'my_actione',
'user_id': '1',
note
};
// 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);
});
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="notes">My note 1</div>
<div class="notes">My note 2</div>
<div class="notes">My note 3</div>
<div class="notes">My note 4</div>
【问题讨论】:
-
Alessio Cantarella 感谢您的编辑,您知道如何完成这项工作吗?
标签: jquery ajax variables foreach send