I'm trying to get this W3 Schools example to work in WordPress.
I already tried this in function.php:
function hook_ajax_script(){
wp_enqueue_script( 'my_ajax_script', get_bloginfo('template_url')."/rscripts/robajax.js" );
}
add_action( 'wp_enqueue_scripts', 'hook_ajax_script' );
add_action( 'admin_enqueue_scripts', 'hook_ajax_script' );
add_shortcode( 'ajax1', 'ajax1_shortcode' );
function ajax1_shortcode( $args ) {
?>
<div id="demo">
<h1>The XMLHttpRequest Object</h1>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>
and my Script
jQuery(document).ready(function(){
jQuery("button").click(function(){
jQuery.ajax({url: "rob.txt", success: function(result){
$("#div1").html(result);
}});
});
});
When I click the Button I get 404 "rob.txt" not found.
I tried it also to do it with a Plugin and rob.txt was inside.
How to get this example to work?