Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- function doAjax(){
- var data1 = jQuery("#data1").val();
- var data2 = jQuery("#data2").val();
- var myajaxurl = '<?php echo admin_url('admin-ajax.php') ?>';
- var data = new FormData();
- //parametro action รจ richiesto da wp-ajax รจ l'hook usato per il match della funzione (wp_ajax_itc_sample_ajax o wp_ajax_nopriv_itc_sample_ajax)
- data.append('action','itc_sample_ajax');
- data.append('method', 'delet');
- data.append('data1', data1);
- data.append('data2', data2);
- jQuery.ajax({
- url: myajaxurl,
- data: data,
- cache: false,
- contentType: false,
- processData: false,
- type: 'POST',
- error: function(json){
- console.log('error');
- },
- success: function(json){
- console.log(json);
- var data = jQuery.parseJSON( json );
- console.log(data);
- }
- });
- </script>
- <?php
- class ItcAjaxSample
- {
- /**
- *
- * @var ItcAjaxSample
- */
- private static $instance = null;
- /**
- *
- * @return ItcAjaxSample
- */
- public static function get_instance() {
- if ( null == self::$instance ) {
- self::$instance = new self;
- }
- return self::$instance;
- }
- protected function __construct() {
- add_shortcode( 'itc_ajax_sample',array($this,'do_ajax_sample'), 10, 2);
- add_action( 'wp_enqueue_scripts', array($this,'enqueue_script') );
- //solo se anche pubblico (no wp-admin)
- add_action( 'wp_ajax_nopriv_itc_sample_ajax', array($this,'itc_sample_ajax') );
- //per wp-admin
- add_action( 'wp_ajax_itc_sample_ajax', array($this,'itc_sample_ajax') );
- }
- public function do_ajax_sample($atts, $content = null ) {
- $a = shortcode_atts( array(
- 'attr1' => null,
- ), $atts );
- $attr1 = $a["attr1"];
- $path = plugin_dir_path(__FILE__) . 'templates/';
- //composer "league/plates": "^3.3"
- $templates = new League\Plates\Engine( $path , "tpl");
- $data = [];
- $data['title'] = "PROVA";
- $data['ajaxurl'] = admin_url('admin-ajax.php');
- $html = $templates->render('itc-pbx-innovaphone-reporting', $data);
- echo $html;
- }
- public function enqueue_script() {
- wp_enqueue_script( 'itc_sample1', plugins_url() . '/myplugin/js/sample.js', array( 'jquery' ), '1.1.1', false );
- wp_enqueue_script( 'itc_sample2', plugins_url() . '/myplugin/js/sample.js', array( 'jquery' ), '1.2.2', false );
- }
- public function itc_sample_ajax(){
- echo json_encode($_POST);
- die();
- }
- }
- $ItcPbxInnovaphoneReporting = ItcPbxInnovaphoneReporting::get_instance();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement