I am working with
and the
will insert text in to the editor on the edit post.
I have two files, one is the
and another one is the
file. I want to call the
function to return the database value to the
.
What I am doing:
<blockquote>
I have [value - X] points. //The Javascript will insert this into the editor. [value - x] is the value which return from the PHP function
</blockquote>
Here is my
:
And here is the
function:
How can I get the value X?
Thx a lot.
Code:
Wordpress
Code:
Javascript
I have two files, one is the
Code:
js
Code:
PHP
Code:
PHP
Code:
Javascript
What I am doing:
<blockquote>
I have [value - X] points. //The Javascript will insert this into the editor. [value - x] is the value which return from the PHP function
</blockquote>
Here is my
Code:
JavaScript
Code:
onsubmit: function( e )
{
var str = '';
if(e.data.friend_cb )
{
str += 'I have [value - X] points. <br><br/>';
}
editor.insertContent(str);
jQuery.ajax({
url: 'http://localhost:8080/wordpress/wp-content/plugins/databaseConnection.php',
type: 'POST',
data: {functionname: 'getX', condition_code: condition_code},
error:function(data)
{
alert("failed");
console.log(data);
},
success: function(data)
{
alert("success");
console.log(data); // Inspect this in your console
}
});
And here is the
Code:
PHP
Code:
if( !isset($_POST['condition_code']) )
{
$error .= 'No function no_friend!';
$condition_code = $_POST['condition_code'];
}
$functionName = $_POST['functionname'];
// $functionName = 'add_bonus_point';
switch($functionName) {
case 'set_no_friend':
//Check did it pass the functionName
if( !isset($_POST['functionname']))
$error .= 'No function name!';
else
$errorBool = false;
break;
case 'try_insert':
getX();
break;
}
function getX()
{
$x = 0;
//Connect to database, get X value.
return $x;
}
How can I get the value X?
Thx a lot.