• Resolved Kline Lozada

    (@klinelozada)


    Hello,

    I would like to know if the plugin is creating a .php file in the file storage after creating a snippet?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Kline Lozada

    (@klinelozada)

    Trying to run a script with the ajax script

    add_action('wp_ajax_my_ajax_hook', 'my_function'); 
    add_action('wp_ajax_nopriv_my_ajax_hook', 'my_function');
    
    add_action( 'wp_enqueue_scripts', 'my_enqueue' );
    function my_enqueue() {
    	$upload_dir = wp_upload_dir();
        wp_enqueue_script( 'ajax-script', $upload_dir['baseurl'] . '/custom-css-js/152152.js', array('jquery') );
        wp_localize_script( 'ajax-script', 'my_ajax_object',
                array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
    }
    
    function my_function() {
    	$_degree = $_POST['degreetype'];
    	$_areainterest = $_POST['areainterest'];
    	$_programlocation = $_POST['programlocation'];
            $_data = json_encode(array("degree" => $_degree, "areainterest" => $_areainterest));
    	wp_send_json_success( $_data );
    	exit();
    }

    I’m also using a plugin called: Simple Custom CSS and JS for the js script

    File: /custom-css-js/152152.js

    jQuery(document).ready(function($){
    	$('.filter-option').change(function() {
    		$.ajax({
    			type: 'POST',
    			dataType: "JSON",
    			url: my_ajax_hook.ajax_url,
    			data: {
    				action: 'my_ajax_hook',
    				degreetype: $('#DegreeType').val(),
    				areainterest: $('#AreaInterest').val(),
    				programlocation: $('#ProgramLocations').val()
    			},
    			success: function(response) {
    				console.log(response.degree);
    			}
    		});
    	});
    });

    The problem is it’s returning error 400, it’s calling the admin-ajax.php but it’s status is 400. So i’m not sure if ajax is allowed to run in this snippet?

    Thanks

    • This reply was modified 2 years, 11 months ago by Kline Lozada.
    Plugin Author Shea Bunge

    (@bungeshea)

    Hello,

    Snippets are currently stored in the database, not as .php files.

    There’s nothing inherent to the plugin that should be preventing you from using AJAX.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Where does the PHP file saved after creating the snippet?’ is closed to new replies.