wip found how to theorically get ajax request in php but for the moment i get error 400
This commit is contained in:
@@ -1,27 +1,21 @@
|
||||
<?php
|
||||
|
||||
function wp_model_plugin_content() {
|
||||
echo "
|
||||
<input type='text' id='mytext'>
|
||||
<button id='mybutton'>send</button>
|
||||
add_files_to_front( array(
|
||||
"menu/menu.js",
|
||||
));
|
||||
|
||||
<script>
|
||||
const inputElement = document.getElementById('mytext');
|
||||
const sendButton = document.getElementById('mybutton');
|
||||
$ajax_url = admin_url( 'admin-ajax.php' );
|
||||
$nonce = wp_create_nonce( 'wp-pageviews-nonce' );
|
||||
add_var_to_front(
|
||||
compact(
|
||||
"ajax_url",
|
||||
"nonce",
|
||||
),
|
||||
"menu"
|
||||
);
|
||||
|
||||
sendButton.addEventListener('click', () => {
|
||||
const inputValue = inputElement.value;
|
||||
const myurl = php_data.ajax_url;
|
||||
console.log(myurl);
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({ data: inputValue })
|
||||
})
|
||||
});
|
||||
</script>
|
||||
";
|
||||
echo create_html("menu/menu.html");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user