Я делаю плагин для WordPress. Плагин добавит tinymce в редактируемое сообщение и отправит post_id в базу данных для дальнейшей идентификации.
В моем случае я пишу javascript, каталог которого находится в wordpress\wp-content\plugins\facebook-api\js\shortcode-tinymce-button.js. И теперь я понятия не имею, как я могу получить post_Id в javascript.
Вот что я делаю:
пользователь нажимает кнопку «ОК» отправляет post_Id и значение текстового поля в базу данных.
(function() {
tinymce.PluginManager.add('facebook_api_tinymce', function( editor, url ) {
editor.addButton( 'facebook_api_tinymce',
{
title: 'Set friend condition',
text: 'Condition',
type: 'menubutton',
menu:
[
{
text: 'Friend',
onclick: function() {
editor.windowManager.open( {
body:[
{
type: 'textbox',
name: 'textboxName',
label: 'Set friend',
value: '20'
}
],onsubmit: function( e ) {
var $hi = "php echo get_the_ID();";
alert($hi);
$no_friend_e = parseInt(e.data.textboxName);
//Pass the value the PHP file, which is doing the database update.
jQuery.ajax({
url: 'http://localhost:8080/wordpress/wp-content/plugins/facebook-api/js/databaseConnection.php',
type: 'POST',
data: {functionname: 'updateDatabase', post_id: '1', no_friend: $no_friend_e},
error:function(data){ //When Can't call the PHP function
alert("failed");
console.log(data);
},
success: function(data) { //update data successful
alert("success");
console.log(data); // Inspect this in your console
}
});
}
});
function get_post_content(id){ //Didn't use
return document.getElementById("post-"+id).innerHTML;
}//you should probably use textContent/innerText but I am not going to get into that here
}
}
]
});
});
Я делаю плагин для WordPress. Плагин добавит tinymce в редактируемое сообщение и отправит post_id в базу данных для дальнейшей идентификации.
В моем случае я пишу javascript, каталог которого находится в wordpress\wp-content\plugins\facebook-api\js\shortcode-tinymce-button.js. И теперь я понятия не имею, как я могу получить post_Id в javascript.
Вот что я делаю:
[list] [*]пользователь нажимает кнопку «ОК» отправляет post_Id и значение текстового поля в базу данных. [img]https://i.sstatic.net/hPe3A.png[/img] [/list]
var $hi = "php echo get_the_ID();"; alert($hi); $no_friend_e = parseInt(e.data.textboxName); //Pass the value the PHP file, which is doing the database update. jQuery.ajax({ url: 'http://localhost:8080/wordpress/wp-content/plugins/facebook-api/js/databaseConnection.php', type: 'POST', data: {functionname: 'updateDatabase', post_id: '1', no_friend: $no_friend_e}, error:function(data){ //When Can't call the PHP function alert("failed"); console.log(data); }, success: function(data) { //update data successful alert("success"); console.log(data); // Inspect this in your console } }); }
});
function get_post_content(id){ //Didn't use return document.getElementById("post-"+id).innerHTML; }//you should probably use textContent/innerText but I am not going to get into that here