I am doing a wordpress plugin for a registration form. I want to validate my form by ajax and jquery. I wrote the ajax/jquery js file and name it user_ajax.js, but when i include it in my main plugin, it doesn't work and $ is not defined error also comes.
please help me i stuck here for 4 days...
Register your script in wordpress like this way http://codex.wordpress.org/Function_Reference/wp_enqueue_script
http://codex.wordpress.org/Function_Reference/wp_register_script
function my_plugin_admin_init() {
/* Register our script. */
wp_register_script( 'my-plugin-script', plugins_url( '/ user_ajax.js', __FILE__ ) );
wp_enqueue_script('jquery'); // Enqueue jQuery that's already built into WordPress
wp_enqueue_script('my-plugin-script');
}
add_action('wp_enqueue_scripts', 'my_plugin_admin_init');
Use the following function as the way in your wordpress plugin file Use jQuery instead of $.
can you please check this wordpress function for register and deregister javascript and css file in wwordpress code
please check this Click Here
Download jquert-1.9.1 and put js file into your project an tha include that file using the script
on to the head part and than make a script tag ex
<html>
<head>
<script src="js/libs/jquery-1.9.1.js"></script>
<script>
$('id or class').click(function){
alert("click");
})
<script>
</head>
<body>
</body>
</html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.