Hi i have this script when link is click the data will be saved into the database. Now my problem is after clicking the link this is the error:
ReferenceError: ajax_object is not defined
This is my script below in single-knowledge page
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".dL").click(function(){
var name = ($(this).attr('name'));
var urldata = ($(this).attr('href'));
var data = {
'action': 'my_action',
'name': name,
'urldata': urldata // We pass php values differently!
};
// We can also pass the url value separately from ajaxurl for front end AJAX implementations
jQuery.post(ajax_object.ajax_url, data, function(response) {
// alert('Got this from the server: ' + response);
alert(response);
});
});
});
</script>
This is my function.php script below
function my_action(){
global $wpdb; // this is how you get access to the database
$name = $_POST['name'];
$url = $_POST['urldata'];
$wpdb->insert('list_of_downloads', array(
'name' => $name,
'filename' =>$url
));
// wp_die(); // this is required to terminate immediately and return a proper response
}
add_action( 'wp_ajax_my_action', 'my_action' );
add_action( 'wp_ajax_nopriv_my_action', 'my_action' ); // <= this one
The problem is this one ajax_object
Can someone help me figured this thing out? Any help is muchly appreciatd.
TIA
ajax_object.ajax_url, you need to useurldata