Thanks for taking a look at my question, firstly, I know this is not the first time a question of this nature has been asked, but I have being reading StackOverflow for over 3 hours now... still can't figure it out.
Here's the gist:
I'm trying to send a value from messaging.php to messaging.js using json_encode.
-> Here's the messaging.php code:
<?php
header('Content-Type: application/json');
global $wpdb;
$current_user = wp_get_current_user();
$to = $_POST['uname'];
$subject = $_POST['subject'];
$message = $_POST['msg'];
$table_name = $wpdb->prefix . 'none_of_ur_business';
if(isset($to) && isset($to) && isset($to)):
$wpdb->insert(
$table_name,
array(
'notit_sender_userid' => $current_user->display_name,
'notit_receiver_userid' => $to,
'notit_subject' => $subject,
'notit_message' => $messagem
)
);
$testtext = 'does this work??';
echo json_encode(array('test' => $testtext));
endif;
Here's the messaging.js code:
function sendMessage(uname, subject, message){
$.ajax({
url : wp_directory+'/modules/messaging/messaging.php',
dataType : 'JSON',
type : 'post',
data: {
'uname' : uname,
'subject' : subject,
'msg' : message
},
success: function(data) {
alert(data.test);
}
});
A couple of relevant things:
- I am developing on the WordPress platform
- I use messaging.php to send data to my database (Maybe that's why, it's not working??)
I don't get anything from the ajax success function, it never "alerts"
Please provide any help you can, I would highly appreciate it!