Support » Fixing WordPress » Added JS file shown in view page, but gives 404 error when clicked

  • Resolved halben

    (@halben)


    After the following code has been created in the child theme’s function.php,

    add_action('wp_enqueue_scripts', 'js_files');
    function js_files() {
    	wp_register_script('ajax_call_mkto', get_template_directory_uri() . 'js/something.js', array('jquery'), false);
    	wp_enqueue_script('ajax_call_mkto');
    }

    I checked the view page source and clicked on the link to see if it works, after clicking it, it gives me a 404 Not Found page. Is there something wrong with my JS file?

    var $k = jQuery.noConflict();
    
    $k('#something .somethinghere("yolo")').click(function() {
    	var $this = $k(this);
    
    	// Ajax call
    	ajaxConnection($this);
    });
    
    function ajaxConnection(item) {
    
    	alert('IT WORKS!');
    
    }

    Thanks,
    Halben

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

    (@halben)

    This is the error I get in the console check:

    404 (Not Found) somewebsite.com/:79
    Resource interpreted as Image but transferred with MIME type text/html

    Thread Starter halben

    (@halben)

    **Okay, I figured it out.**

    I had my scripts folder in the child theme directory. Instead of using “get_template_directory_uri()”, which gets the directory from the parent’s theme folder, I have to user “get_stylesheet_directory_uri()” to get the fold from the child theme.

    Thanks for the assistance! It was my small mistake.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Added JS file shown in view page, but gives 404 error when clicked’ is closed to new replies.