在以下模板中,我想将RESULT传递给programmatically_create_post(RESULT)函数;
<?php
/*
Template Name: Play
* The template for displaying all pages.
*
*/
get_header();
$base = get_stylesheet_directory_uri() . '/xxxxx';
?>
<div ...
<html>
<head>
<link rel="stylesheet" href="<?php echo $base; ?>/css/xxxxx.css" />
<script src="<?php echo $base; ?>/js/xxxxx.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="<?php echo $base; ?>/js/xxxxx.js"></script>
</head>
<body>
<div id="board" style="width: 400px"></div>
<p>A: <span id="a"></span></p>
<script>
var init = function() {
...
RESULT = $('#a'),
...
RESULT.html(a);
};
...
};
jQuery(document).ready(init);
jQuery(document).ready(function($) {
// We'll pass this variable to the PHP function programmatically_create_post
var fruit = 'Banana';
// This does the ajax request
$.ajax({
//url: ajaxurl,
data: {
'action':'programmatically_create_post',
'fruit' : fruit
},
success:function(data) {
// This outputs the result of the ajax request
console.log(data);
},
error: function(errorThrown){
console.log(errorThrown);
}
});
});
</script>
</body>
</html>
<?php
...
$post_id = programmatically_create_post(RESULT);
...
RESULT是一个由javascript返回的字符串。
&#34; A:&#34;显示结果。
当我$post_id = programmatically_create_post("essai");
工作时,帖子是用&#34; essai&#34;创建的。
如何将RESULT发送到programmatically_create_post函数?