Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Wordpress Ajax callback action
  2. add_action('wp_ajax_chat_comms', 'chat_comms');
  3.  
  4. function chat_comms(){
  5.  
  6. //no nounce for the moment, just test data is being received ok....
  7.  
  8. $message= $_POST['txt'];
  9.  
  10. if($message){
  11. echo $message;
  12. } else {
  13. echo 'the function is called correctly so we know ajax url and the action parameter is ok, sadly we have miss spelled the post variable or have a issue with our ajax method..';
  14. }
  15.  
  16. exit; // no trailing 0's
  17. }
  18.  
  19.  
  20.  
  21.  
  22. // lets load a new js file to rule out caching issues....
  23.  
  24. function load_chat_me_styles(){
  25. $pldir=get_site_url().'/wp-content/plugins/chat_me/';
  26. wp_enqueue_style( 'chat_me-style', $pldir.'css/chat_me.css' );
  27. wp_enqueue_script('chat_me-script', $pldir.'js/newchat_me.js', array('jquery') ); // --> note file name for js file + lets be sure we wait for jquery to be loaded....
  28. wp_localize_script( 'chat_me-script', 'chat_ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ))); .. not being used in the script --> if ajaxurl is undefined replace with chat_ajax.ajaxurl
  29. }
  30. add_action( 'admin_enqueue_scripts', 'load_chat_me_styles' ); //-->note changed hook!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement